Custom Serilog configuration

Introduction

Illustrates customizing logging by configuring Serilog targets and rules.

Configure Serilog

Log.Logger = new LoggerConfiguration()
    .WriteTo.Console()
    .WriteTo.File(logFilePath)
    .CreateLogger();

Pass that configuration to NServiceBus

LogManager.Use<SerilogFactory>();

var endpointConfiguration = new EndpointConfiguration("Samples.Logging.SerilogCustom");

Ensure logging is flushed on shutdown

await endpointInstance.Stop()
    .ConfigureAwait(false);
Log.CloseAndFlush();

Related Articles

  • Logging
    Manage and integrate with NServiceBus logging.
  • Serilog Tracing
    Writing diagnostic log entries via Serilog Tracing.

Last modified