I am usually using injection with Serilog and ILogger but in this case I hade to create my own ILogger like this :
private static readonly ILogger _logger = Serilog.Log.ForContext<MyClass>() as ILogger;
I do however need a Microsoft ILogger instead, is there any way to create a Microsoft ILogger from Serilog or to convert a existing Serilog ILogger to Microsoft ILogger?
Edit 1: To be clear, the project is a .net microservice that use "IHostBuilder.UseSerilog" to feed the injection of Microsoft ILogger to classes. In this specific case I can however not have a ILogger injected, this would create a circular relation. So to solve this I have to manually create it within the context(example above).
The problem is that this creates a Serilog ILogger while the method I need to use takes a Microsoft ILogger.
So either I need to convert the Serilog ILogger to a Microsoft ILogger or even better, get Serilog to create a Microsoft ILogger.
Actually, best would be if I could avoid adding more Serilog stuff into the code, it makes it harder if the log system later need to be switched.
Edit 2:
I have tried this :
var logger1 = Serilog.Log.ForContext<MessageQueueSink>() as Serilog.ILogger;
logger1.Information("test1");
var loggerFactorytest = new LoggerFactory()
.AddSerilog(logger1);
var logger2 = loggerFactory.CreateLogger("Logger");
logger2.LogInformation("test2");
The first "test1" is shown in the output but the "test2" is not. its now leaning more and more toward excluding logging from this part of the code.