Recencely I discoverd serilog ( structured logging for .net ) and saw a lot of its advantages. But I face some problems with it. I have 4 projects, one is web, one is infrastructure and the other two are windows services, I want to declare serilog configuration once and use it multiple times. And also I want to use it with dependency injection. I have been searching web for three days now, but I did not find any thing useful, please some one help me.
For example I want this class to be my logging class.
public interface IMyLogger
{
void Information(string message, object[] parameters);
}
public class MyLogger : IMyLogger
{
public MyLogger()
{
}
public void Information(string message, object[] parameters)
{
Log.Information("LogType : {LogType} - Operation : {Operation}", parameters);
}
}
public class UserClass
{
private readonly IMyLogger _myLogger;
public UserClass(IMyLogger myLogger)
{
_myLogger = myLogger;
}
}
Now I don't know where I should put this line of code:
Log.Logger = new LoggerConfiguration()
.WriteTo.Console()
.CreateLogger();
Tnx in advance.