log4net

Sentry has an integration with log4net through the Sentry.Log4Net NuGet package.

Without any code change, this package is able to initialize the Sentry SDK and capture events while including additional properties like Exception data and more.

Installation

Using package manager:

Install-Package Sentry.Log4Net -Version 1.0.0

Or using the .NET Core CLI:

dotnet add Sentry.Log4Net -v 1.0.0

This package extends Sentry main SDK. That means besides the log4net Appender, through this package you’ll also get access to all API and features available in the main Sentry SDK.

Configuration

Once the log4net integration package is installed in your project, you can modify your configuration file to add the appender. This can be done, for example, via the app.config for console and desktop apps or web.config in case of ASP.NET.

  <appender name="SentryAppender" type="Sentry.Log4Net.SentryAppender, Sentry.Log4Net">
      <Dsn value="___PUBLIC_KEY___"/>
      <!--Sends the log event Identity value as the user-->
      <SendIdentity value="true" />
      <threshold value="INFO" />
    </appender>

SendIdentity

In the example above, the SendIdentity flag was switched on. The SDK then will take the log4net Identity value and report to Sentry as the user’s id.

Dsn

Also in the example above, you can find the DSN being set. That will instruct the SentryAppender to initialize the SDK.

NOTE: This is only one of the ways to initialize the SDK. If you wish to configure the SDK programatically, you could leave the DSN out from the appender configuration section. The SDK needs to be initialized only once and since other integrations (like ASP.NET) are also able to initialize the SDK, you only need to pass the DSN to one of these integrations.

Sample

For a sample app.config or a complete working sample to see it in action.

Sample event in Sentry