Asaf Epelbaum
Asaf Epelbaum

Reputation: 586

ASP.NET - Serilog - Multiple sinks each one for a different use

I want to use Serilog for logging because I worked with it and it fits my needs.

The difference in this case is that I need to log different modules and I would like each module to be logged in a different folder and even maybe in a different sink.

I am not talking about using several sinks, but I talk about doing something like this:

Serilog.Log(LogInstance1,"Log for module 1") // Logs in a rolling text file in folder X 10 files of 1MB each
Serilog.Log(LogInstance2,"Log for module 2") // Logs i na text file that doesn't delete old entries

Does anyone know if this is possible to achieve with Serilog?

Upvotes: 9

Views: 4921

Answers (1)

Ruben Bartelink
Ruben Bartelink

Reputation: 61795

You can make multiple separate ILogger instances, each with their own configuration and set of sinks etc.; each pipeline operates completely separately with no shared state of any kind.

var logger1 = new LoggerConfiguration().
    .WriteTo.File(...10...)
    .CreateLogger();

var logger2 = new LoggerConfiguration()
    .WriteTo.File(...)
    .CreateLogger();

logger1.Information("Log for Module 1");
logger2.Information("Log for Module 2");

Upvotes: 8

Related Questions