Skip to content

Mimeo/serilog-sinks-newrelic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

A Serilog sink that writes events to the NewRelic apm application.

Getting started

Install NewRelic NuGetPackage

Configure NewRelic Settings:

  <appSettings>
    <add key="NewRelic.LicenseKey" value="<API Key here>"/>
    <add key="NewRelic.AgentEnabled" value="true"/>
    <add key="NewRelic.AppName" value="Serilog.Sinks.NewRelic.Sample"/>
  </appSettings>

Point the logger to NewRelic:

Log.Logger = new LoggerConfiguration()
    .WriteTo.NewRelic(applicationName: "Serilog.Sinks.NewRelic.Sample")
    .CreateLogger();

And use the Serilog logging methods to associate named properties with log events:

Log.Error("Failed to log on user {ContactId}", contactId);

The sink also supports sending Serilog.Metrics to NewRelic although this requires a custom transaction in NewRelic See here and may turn out to be largely redundant!

// Adding a custom transaction

using (logger.BeginTimedOperation("Time a thread sleep for 2 seconds."))
{
    Thread.Sleep(1000);
    using (logger.BeginTimedOperation("And inside we try a Task.Delay for 2 seconds."))
    {
        Task.Delay(2000).Wait();
    }
    Thread.Sleep(1000);
}

About

A Serilog sink that writes events to NewRelic

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages