log4net method GetLogger() Equivalent in Serilog

隐身守侯 提交于 2021-02-10 10:57:45

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!