ThiagoBarradas / serilog-sinks-newrelic-logs

A Serilog sink that writes events to the NewRelic Logs.
https://www.nuget.org/packages/Serilog.Sinks.NewRelic.Logs
Other
31 stars 15 forks source link
apm dotnet-core dotnet-core2 dotnet-core3 dotnet-framework dotnet-standard log new-relic newrelic serilog sink

Build Status NuGet Downloads NuGet Version Quality Gate Status

A Serilog sink that writes events to the NewRelic Logs.

Getting started

Log.Logger = new LoggerConfiguration()
    .WriteTo.NewRelicLogs(
        endpointUrl: "https://log-api.newrelic.com/log/v1", 
        applicationName: "Serilog.Sinks.NewRelic.Sample", 
        licenseKey: "[Your API key]")
    .CreateLogger();

If you have new relic agent and use environment variables NEW_RELIC_APP_NAME and NEW_RELIC_LICENSE_KEY, you can do just:

Log.Logger = new LoggerConfiguration()
    .WriteTo.NewRelicLogs()
    .CreateLogger();

The available parameters are:

The events are submitted to NewRelic Logs in batches, and the sink is derived from PeriodicBatchingSink. It therefore supports the following parameter:

The batches are formatted using NewRelic Logs detailed JSON body and are transmitted GZip-compressed.

All properties along with the rendered message will be emitted to NewRelic Logs. This sink adds four additional properties:

If newrelic.linkingmetadata property is present in an event, it will be unrolled into individual NewRelic properties used for "logs in context".

Install via NuGet

PM> Install-Package Serilog.Sinks.NewRelic.Logs

JSON configuration

It is possible to configure the sink using Serilog.Settings.Configuration by specifying the license key and other desired parameters in appsettings.json:

{
  "Serilog": {
    "Using": [ "Serilog.Sinks.NewRelic.Logs" ],
    "WriteTo": [
      {
        "Name": "NewRelicLogs",
        "Args": {
          "applicationName": "NewRelicLogTestSample",
          "licenseKey": "58e9892abd3f09d91b0db0d0e9e95628FFFFNRAL"
          //... other parameters
        }
      }
    ],
    "Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId", "WithNewRelicLogsInContext" ]
  }
}

Contributors

This code is based on https://github.com/stanisls/serilog-sinks-newreliclogs

Thanks @stanisls and @johnkattenhorn :muscle:

How can I contribute?

Please, refer to CONTRIBUTING

Found something strange or need a new feature?

Open a new Issue following our issue template ISSUE_TEMPLATE

Changelog

See in nuget version history

Did you like it? Please, make a donate :)

if you liked this project, please make a contribution and help to keep this and other initiatives, send me some Satochis.

BTC Wallet: 1G535x1rYdMo9CNdTGK3eG6XJddBHdaqfX

1G535x1rYdMo9CNdTGK3eG6XJddBHdaqfX