How to pass compile-time logging source generation code method input as serilog.Ilogger instead of Extensions.Logging?

83 views Asked by At

Below is sample code for passing Microsoft.Extensions.logging as input of logging partial method.but my scenarios is how pass Serilog.Ilogger as input of logging partial method.

  [LoggerMessage(EventId = 0, Level = LogLevel.Information, Message = "Generating {customer}")]
    private static partial void LogCustomerCreated(
ILogger logger, [LogProperties] Customer customer);
1

There are 1 answers

0
Gesuele Russello On

To use Serilog with Microsof.Extention.Loggin you need to use this package "Serilog.Extensions.Logging".

You then need to create the Ilogger with LoggerFactory

SerilogLoggerFactory loggerFactory = new SerilogLoggerFactory();

ILogger<Program> newLogger = loggerFactory.CreateLogger<Program>();
DataProcessor dataProcessor = new(loggerFactory.CreateLogger<DataProcessor>());

Can you share more information about the part where you create the log