SoFunction
Updated on 2025-03-07

Methods using Exceptionless in C#

background

The definition of the word "Exceptionless" is: without exception. Exceptionless provides real-time error reporting for your JavaScript, Node, .NET Core, Web API, WebForms, WPF, console and MVC applications. It organizes the collected information into simple actionable data that will help your application become abnormal!

Exceptionless focuses on real-time configurability, which distinguishes it from other error monitoring services. If someone else might need to change the configuration in your code and redeploy the application, Exceptionless allows you to make changes without changing the deployed code.

getting Started

Exceptionless provides you with tools to track errors, logs, and events while guiding you to find a viable solution. First, you need to determine if you are hostless or using our managed version. If you choose to use our hosted version, you can get started for free.

Hosting Options

create an account

After registering, you will be prompted to create the first project.

Configure your application by clicking the Download and Configure Client action button on the project list page.

Select your project type and follow the instructions.

Your application will now automatically send all unhandled errors to the Exceptionless service.

You can also send processed errors, feature usage or log messages, and other information (see documentation for specific clients).

Self-hosted options

We have compiled a comprehensive documentation to help you get started with a self-hosted Exceptionless instance. You can find the document here.

Send your first event#
Once the account has been determined and the project has been created, the event can be started. Let's take a look at sending a simple event to Exceptionless.

Power-on self-testapi/v2/events

curl --location --request POST "/api/v2/events" \
--header 'Authorization: Bearer YOUR_PROJECT_TOKEN' \
--header 'Content-Type: application/json' \
--data-raw '{ "type": "error", "date":"2030-01-01T12:00:00.0000000-05:00", "@simple_error": { "message": "Simple Exception", "type": "", "stack_trace": " at () in :line 77" } }'

You have created an account, what about now? Let's start with your project setup, and then we'll dig into some best practices and methods to enhance your use of Exceptionless.

Client Integration

ExceptionlessClient configuration number

The following example shows various ways (configuration files, properties, or code) that can be configured in an application.

Configuration and code

using Exceptionless;

var client = new ExceptionlessClient(c => {
   = "YOUR_API_KEY";
  (version);
});

// You can also set the api key directly on the default instance.
 = "YOUR_API_KEY"

Configuration and Properties

You can also configure Exceptionless with the following properties:

using ;
[assembly: Exceptionless("YOUR_API_KEY")]

This property is selected only if the Exceptionless assembly property is defined in the entry or invoked assembly. If you place the above attributes elsewhere, you need to call the following method during startup.

using Exceptionless;
(typeof(MyClass).Assembly)

Configuration and environment variables

You can also add environment variables or application settings and use the key names Exceptionless:ApiKey and yourYOUR_API_KEY as values.

Used

The config part can be configured using or without exception, depending on the type of project you have. The necessary configuration elements should be added automatically when installing the correct NuGet package. It should look like this:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
 <configSections>
  <section name="exceptionless" type=", Exceptionless" />
 </configSections>
 <!-- attribute names are cases sensitive -->
 <exceptionless apiKey="API_KEY_HERE" />
 ...
 <>
  <modules>
   <remove name="ExceptionlessModule" />
   <add name="ExceptionlessModule" type=", " />
  </modules>
  ...
 </>
</configuration>

Version number

By specifying the application version, you can enable additional features. By default, the application version is attempted to be parsed from the assembly properties. However, it is best to specify the application version using the following code.

using Exceptionless;
("1.2.3");

Offline storage

Events can also be persisted to disk for offline situations, or ensure that no events are lost between application restarts. When selecting a folder path, make sure that the identity under which the application runs has full permissions to the folder.

Note that this adds some overhead, as events need to be serialized to disk at commit time and are not recommended for high-throughput logging schemes.

Configuration file number

<!-- Use Folder Storage -->
<exceptionless apiKey="YOUR_API_KEY" storagePath="PATH OR FOLDER NAME" />

Code

// Use folder storage
("PATH OR FOLDER NAME");
// Use isolated storage
();

Disable without exception

You can use the Enabled setting to disable Exceptionless reporting events during testing.

Configuration file number

<exceptionless apiKey="YOUR_API_KEY" enabled="false" />

Attribute number

using ;
[assembly: Exceptionless("YOUR_API_KEY", Enabled=false)]

Self-hosted options

The Exceptionless client can also be configured to send data to your self-hosted instance. Configure it by setting the settings serverUrl to point to your Exceptionless instance.

Configuration file number

<exceptionless apiKey="YOUR_API_KEY" serverUrl="http://localhost" />

Attribute number

using ;
[assembly: Exceptionless("YOUR_API_KEY", ServerUrl = http://localhost)]

/exceptionless/Exceptionless

The above is the detailed content of the method of using Exceptless in C#. For more information about using Exceptless in C#, please follow my other related articles!