问题
Brief Backround
We are replacing in our project the log4net
to Serilog
. In many of our classes we are using the method LogManager.GetLogger
of log4net when giving as a parameter the class name using MethodBase.GetCurrentMethod().DeclaringType
, so we could know in which class the log was written.
My Question Is
Is there any method which is equivalent in Serilog which can give me the logger? I know that there is the option of ForContext()
which you can specify the class you're in, but I still don't know how to get an instance of a logger without some kind of logManager.
P.S
To give a logger as a parameter to each class constructor (instead of using Getlogger()
) would take some time and I would really prefer to avoid this option.
回答1:
After I did some research, I founded out that there is NO Log4Net
GetLogger() equivalent in Serilog.
回答2:
What about the SourceContext Property wich is set in a context? https://github.com/serilog/serilog/issues/91
来源:https://stackoverflow.com/questions/51191454/log4net-method-getlogger-equivalent-in-serilog