Open source logging framework Exceptionless Tutorial

Exceptionless is a logging framework, it is open source, free, provide management interface that is easy to install and use. ExceptionLess bottom using ElasticSearch as a log storage provides fast, rich query API, to facilitate our system integration. This article describes the common usage of ExceptionLess.

Installation ExceptionLess

In ExceptionLess official website provides based Docker privatization deployment, we can install a test environment in the manner official website.

  1. Download the latest release in the official website github package, the address: https://github.com/exceptionless/Exceptionless/releases
  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 see the vessel running in the Kitematic
  3. Follow the official website of the 5000 port is the landing page, but the reality is that 5000 is API, 5100 is the landing page, so we open http: // localhost: 5100 to enter the login page. Note: This may be related with the version, see the port mapping docker at the time of use.

Through the above steps, you build a good test in the local environment. We can start to see the start of a total of six vessels, which are redis, elasticsearch, kibana, Exceptionless Job, Exceptionless Api, Excetpionless UI.

Quick Start

After the test environment to build a good, first visit Exceptionless UI to create users, organizations and projects. Then, when the project is created, Exceptionless will jump to the client configuration page, to guide how we use Exceptionless client. We can choose to use the client's own needs, to complete the client configuration through the guidance of the page.

Boot page is as follows:

image

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

Client API: https://github.com/exceptionless/Exceptionless.Net/wiki

After configured, we can log the, 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
ExceptionlessClient.Default.SubmitFeatureUsage("MyFeature");
ExceptionlessClient.Default.CreateFeatureUsage("MyFeature").AddTags("Exceptionless").Submit();

// Submit a 404
ExceptionlessClient.Default.SubmitNotFound("/somepage");
ExceptionlessClient.Default.CreateNotFound("/somepage").AddTags("Exceptionless").Submit();

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

Features

Exceptionless events in the following types:

  • Log messages: the log records, can be any text content
  • Use Characteristics: recording usage functions, like for example the case of interface calls
  • Anomalies: abnormal recording information
  • Broken Link: record when the page is accessed does not exist

In addition to the recorded content outside, Exceptionless also add support for event tags, additional data, a user operation and the like is described, for example, (code from official website):

try {
    throw new ApplicationException("Unable to create order from quote.");
} catch (Exception ex) {
    ex.ToExceptionless()
        // 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();
        .SetReferenceId(Guid.NewGuid().ToString("N"))
        // 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.
        .AddTags("Order")
        // Mark critical.
        .MarkAsCritical()
        // 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.
        .Submit();
}

NLog, Log4net 集成

Official support NLog, Log4net integrated support, just add the appropriate configuration file logging component can be. To Log4net example:

Start by adding support assembly:

Install-Package Exceptionless.Log4net

And configure (code from official website) in log4net profile:

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

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

API interface

In addition to the rich client functionality, Exceptionless also provides a number of API support, the API can be accessed on port 5000. Address: HTTP: // localhost: 5000 / docs / index.html, shots are as follows :

image

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

Reference material

Guess you like

Origin www.cnblogs.com/youring2/p/11546485.html