Open source logging framework Exceptionless usage tutorial

Open source logging framework Exceptionless usage tutorial

Exceptionless is a logging framework. It is open source, free, provides a management interface, and is easy to install and use. The bottom layer of ExceptionLess uses ElasticSearch as log storage and provides fast and rich query APIs to facilitate system integration. This article will introduce the common usage of ExceptionLess.

Install ExceptionLess

The ExceptionLess official website provides a Docker-based privatized deployment method, and we can install the test environment according to the official website.

  1. Download the latest release package from the official website github, address:
  2. Decompress, and then enter the unzipped directory, execute the docker-compose up -dcommand to start a plurality of containers in the background, when the execution is completed, Exceptionless already up and running locally. We can view the running container in Kitematic
  3. According to the instructions on the official website, port 5000 is the login page, but in reality, 5000 is the API, and 5100 is the login page, so we open http://localhost:5100 to enter the login page. Note: This may be related to the version. Check the port mapping of docker when using it.

Through the above steps, the test environment is set up locally. We can see that a total of 6 containers have been started, namely redis, elasticsearch, kibana, Exceptionless Job, Exceptionless Api, and Excetpionless UI.

Get started quickly

After setting up the test environment, first visit the Exceptionless UI to create users, organizations and projects. Then, when the project is created, Exceptionless will jump to the client configuration page to guide us how to use the Exceptionless client. We can choose the client we need to use, and complete the client configuration through the instructions on the page.

The guide page is as follows:

In this way, we can complete the configuration of the .Net platform project and JS project.

Client API:

After the configuration is complete, we can record the log, for example (the code comes from the official website):

//Import the exceptionless namespace.
using Exceptionless;

//Submit logs
ExceptionlessClient.Default.SubmitLog("Logging made easy");

//You can also specify the log source and log level.
//We recommend specifying one of the following log levels: Trace, Debug, Info, Warn, Error
ExceptionlessClient.Default.SubmitLog(typeof(Program).FullName, "This is so easy", "Info");
ExceptionlessClient.Default.CreateLog(typeof(Program).FullName, "This is so easy", "Info").AddTags("Exceptionless").Submit();

//Submit feature usages

//Submit a 404

//Submit a custom event type
ExceptionlessClient.Default.SubmitEvent(new Event {Message = "Low Fuel", Type = "racecar", Source = "Fuel System" });


There are several types of events in Exceptionless:

  • Log message: The recorded log, which can be any text content
  • Feature usage: record of function usage, such as interface call status, etc.
  • Abnormal situation: record abnormal information
  • Invalid link: record when the visited page does not exist

In addition to recording content, Exceptionless also supports operations such as adding tags, additional data, and user descriptions to events, for example (the code comes from the official website):

try {
    throw new ApplicationException("Unable to create order from quote.");
} catch (Exception ex) {
       //Set the reference id of the event so we can search for it later (reference:id).
       //This will automatically be populated if you call ExceptionlessClient.Default.Configuration.UseReferenceIds();
       //Add the order object but exclude the credit number property.
        .AddObject(order, "Order", excludedPropertyNames: new [] {"CreditCardNumber" }, maxDepth: 2)
       //Set the quote number.
        .SetProperty("Quote", 123)
       //Add an order tag.
       //Mark critical.
       //Set the coordinates of the end user.
        .SetGeo(43.595089, -88.444602)
       //Set the user id that is in our system and provide a friendly name.
        .SetUserIdentity(user.Id, user.FullName)
       //Set the users description of the error.
        .SetUserDescription(user.EmailAddress, "I tried creating an order from my saved quote.")
       //Submit the event.

NLog, Log4net integration

The official support for NLog, Log4net integration support, you only need to add the configuration file of the corresponding log component. Take Log4net as an example:

First add support for the assembly:

Install-Package Exceptionless.Log4net

Then configure it in the log4net configuration file (the code comes from the official website):

<appender name="exceptionless" type="Exceptionless.Log4net.ExceptionlessAppender,Exceptionless.Log4net">
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%-4timestamp [%thread] %-5level %logger %ndc-%message%newline"/>

  <level value="DEBUG"/>
  <appender-ref ref="exceptionless"/>

API interface

In addition to rich client functions, Exceptionless also provides support for a large number of APIs, which can be accessed on port 5000. The address is: http://localhost:5000/docs/index.html, the screenshot is as follows :

Through these interfaces, we can implement more customized operations, such as user authorization, project management, log query and other operations.


My blog will be synced to Tencent Cloud + community soon, I invite everyone to join us:

Reference: Open source logging framework Exceptionless tutorial-Cloud + Community-Tencent Cloud