/serilog-extensions-logging-applicationinsights

Add application insights logging to ASP.NET Core apps with one line of code.

Primary LanguageC#Apache License 2.0Apache-2.0

Serilog.Extensions.Logging.ApplicationInsights

Build status NuGet Version

This package makes it a one-liner - loggerFactory.AddApplicationInsights() - to configure top-quality application insights logging for ASP.NET Core apps.

You can get started quickly with this package, and later migrate to the full Serilog API if you need more sophisticated log configuration.

appsettings.json configuration

The log level and instrumentation key can be read from JSON configuration if desired.

In appsettings.json add a "Logging" and "ApplicationInsights" section:

{
  "Logging": {
    "LogLevel": {
      "Default": "Debug",
      "System": "Information",
      "Microsoft": "Information"
    }
  },
  "ApplicationInsights": {
    "InstrumentationKey": "your-Instrumentation-key"
  }
}

And then pass the configuration sections to the AddApplicationInsights() method:

loggerFactory.AddApplicationInsights(Configuration.GetSection("Logging"), Configuration.GetSection("ApplicationInsights"));

HINT: The "Logging" and "ApplicationInsights" sections are standard section already used by netcore.

Using the full Serilog API

This package is opinionated, providing the most common/recommended options supported by Serilog. For more sophisticated configuration, using Serilog directly is recommended.