项目作者: tanaka-takayoshi

项目描述 :
A serilog sink that sends logs to New Relic Logs
高级语言: C#
项目地址: git://github.com/tanaka-takayoshi/Serilog.Sinks.NewRelicLab.Logs.git
创建时间: 2020-03-08T06:49:48Z
项目社区:https://github.com/tanaka-takayoshi/Serilog.Sinks.NewRelicLab.Logs

开源协议:Apache License 2.0

下载


Serilog.Sinks.NewRelicLab.Logs

A serilog sink that sends logs to New Relic Logs

.NET Core

Note: This is an unofficial package. Since this is an experimental library, please consider using more robust log shipping method (e.g. fluentd).

Requirements

  • New Relic Logs subscription (License Key or Insert API key is required)
  • New Relic APM subscription if you’d like to enable Logs in Context
  • Serilog 2.5.0 or above (Serilog will be installed as one of dependencies)

Usage

  1. Add Serilog.Sinks.NewRelicLab.Logs package.

  2. Use NewRelicLogs() extentione method to configure. Here is an example code using with ASP.NET Core.

    1. using NewRelic.LogEnrichers.Serilog; //This using is required for `WithNewRelicLogsInContext` method.
    2. using Serilog.Sinks.NewRelicLab.Logs;
    1. Log.Logger = new LoggerConfiguration()
    2. .Enrich.FromLogContext()
    3. .Enrich.WithNewRelicLogsInContext()
    4. .WriteTo.NewRelicLogs()
    5. .CreateLogger();
  3. Add one of the following ENVIRONMENT VARIABLE to start the process: NEW_RELIC_LICENSE_KEY is for a New Relic License Key, or NEW_RELIC_INSERT_KEY is for an Insert API key.

  4. Output your log with Serilog.

    1. Serilog.Log.Information("Web Host launched!");
  5. You will see your log in New Relic Logs.

Troubleshooting

Enabling Selflog in Serilof will help you what’s happing.

  1. var file = File.CreateText(@"./selflog.txt");
  2. Serilog.Debugging.SelfLog.Enable(TextWriter.Synchronized(file));