Skip to content

NuGet package that simplifies logging to Papertrail in NET.Core

License

Notifications You must be signed in to change notification settings

OlivierBouchoms/Bouchoms.Extensions.Logging.Papertrail

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bouchoms.Extensions.Logging.Papertrail

NuGet package that simplifies logging to Papertrail when using Microsoft.Extensions.Logging.

Getting started

NuGet

https://www.nuget.org/packages/Bouchoms.Extensions.Logging.Papertrail/

.NET 8

dotnet add package Bouchoms.Extensions.Logging.Papertrail --version 8.0.0

For development environments, add the configuration to your appsettings.json file. This feature is not safe for realworld usage. Refer to Security and user secrets documentation to safely configure the credentials for realworld usage.

{
  "Bouchoms.Extensions.Logging.Papertrail": {
    "AccessToken": "your-access-token",
    "Url": "your-papertrail-url"
  },
}

.NET 6

dotnet add package Bouchoms.Extensions.Logging.Papertrail --version 6.0.0

For development environments, add the configuration to your appsettings.json file. This feature is not safe for realworld usage. Refer to Security and user secrets documentation to safely configure the credentials for realworld usage.

{
  "Bouchoms.Extensions.Logging.Papertrail": {
    "AccessToken": "your-access-token",
    "Url": "your-papertrail-url"
  },
}

Code

In your Startup class:

var builder = WebApplication.CreateBuilder(args);

builder.Logging.ClearProviders();
builder.Logging.AddConsole();
builder.Logging.AddPapertrail();

builder.Services.AddOptions<PapertrailOptions>()
                .Bind(builder.Configuration.GetSection(PapertrailOptions.ConfigurationSection))
                .ValidateDataAnnotations();

The logger provider is registered using the Papertrail alias. This makes it possible to customize logging behavior per scope.

{
  "Logging": {
    "LogLevel": { // No provider, LogLevel applies to all the enabled providers.
      "Default": "Error",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Warning"
    },
    "Debug": { // Debug provider.
      "LogLevel": {
        "Default": "Information" // Overrides preceding LogLevel:Default setting.
      }
    },
    "Papertrail": { // Papertrail provider.
      "LogLevel": {
        "Microsoft": "Information"
      }
    }
  }
}

See Logging in .NET Core and ASP.NET Core for more information.