• /
  • Log in
  • Free account

.NET: Configure with Serilog

Use our Serilog extension to link to your log data with related data across the rest of the New Relic platform. Read on to learn how to configure logs in context and enrich your log data.

Compatibility and requirements

To use New Relic logs in context with Serilog, ensure your configuration meets the following requirements:


Serilog is a structured logging framework that records log messages from your application and creates a LogEvent to store the message data. Using Enrichers, you can add additional information to the log events, while Sinks and Formatters allow you to format and output those log events for downstream consumption and viewing.

This diagram illustrates the flow of log messages through Serilog.

Logs-in-context Serilog

This diagram illustrates the flow of log messages through Serilog, highlighting specific components of the New Relic Serilog extension.

The above diagram highlights several components of the Serilog extension:

  • New Relic Enricher: The NewRelicEnricher adds contextual information from the .NET agent (using the API) to the log events generated by the application. This contextual information, known as linking metadata, is used by New Relic to link log messages to the transactions and spans from which they were created.
  • New Relic Formatter: The NewRelicFormattertranslates enriched log events into the JSON format expected by New Relic. A sink instructs Serilog to output the JSON to a file in the location that the Log Forwarder expects.
  • New Relic Log Forwarder: The NewRelicFormattertranslates enriched log events into the JSON format expected by New Relic. A sink instructs Serilog to output the JSON to a file in the location that the log forwarder expects. The example below uses the New Relic Fluentd log forwarded, however there are many other log forwarders that can be used. For more information, see Introduction to log management.

For more information about Serilog log events, see the Serilog Getting started documentation.

Configure logs in context with log management

To configure New Relic logs in context with Serilog:

  1. Enable log management with a compatible log forwarding plugin.
  2. Install or update the .NET agent.
  3. Configure the Serilog extension.
  4. Check for logging data.

Enable log management

Confirm that you have log management enabled, with a compatible log forwarding plugin installed to send your application logs to New Relic.

Install or update the .NET agent

Install or update to the most recent .NET agent version, and enable Distributed tracing.

Configure the Serilog extension

To configure logs in context with the Serilog extension, complete the following steps:

  1. Using the Visual Studio NuGet Package Manager, locate and install the NewRelic.LogEnrichers.Serilog package.

  2. In your application code, update your logging configuration to add the NewRelicEnricher and NewRelicFormatter.

    The following code example enriches log events with New Relic linking metadata. In addition to the existing log files, it outputs new log files in a specific JSON format at C:\logs\SerilogExample.log.json for consumption by the Log Forwarder:

    var loggerConfig = new LoggerConfiguration()
    .WriteTo.File( path: @"C:\logs\ExistingLoggingOutput.txt")
    formatter: new NewRelicFormatter(),
    path: @"C:\logs\SerilogExample.log.json");
    var log = loggerConfig.CreateLogger();


    The above configuration results in new JSON files that are written to disk. Some of these configuration options may be useful in managing the amount of disk space used and/or the performance of the sink.

    • restrictedToMinimumLevel
    • buffered
    • rollingInterval
    • rollOnFileSizeLimit
    • retainedFileCountLimit


    Though not required, using the Serilog Asynchronous Sink Wrapper may help improve the performance by performing formatting and output of log files on a different thread.

  3. Once you have configured the Serilog extension and updated your logging file, you can configure your extension to send data to New Relic Logs. See below for an example of this configuration using the Fluentd plugin for New Relic Logs:

    @type tail
    path C:\logs\SerilogExample.log.json
    pos_file C:\logs\SerilogExample.log.json.pos
    tag logfile.*
    @type json
    <match **>
    @type newrelic
    license_key <YOUR NEW_RELIC_LICENSE_KEY>
    base_uri https://log-api.newrelic.com/log/v1

File-based configuration

Configuration of the New Relic Logs Serilog extension may also be accomplished with file-based configuration providers.

What's next?

Now that you've set up APM logs in context, here are some potential next steps:

For more help

If you need more help, check out these support and learning resources:

Create issueEdit page
Copyright © 2021 New Relic Inc.