log4net方法GetLogger

log4net方法GetLogger

本文介绍了log4net方法GetLogger()在Serilog中等效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在项目中将 log4net 替换为 Serilog .在我们的许多类中,使用 MethodBase.GetCurrentMethod().DeclaringType 作为类名称作为参数时,我们使用log4net的 LogManager.GetLogger 方法.日志写在哪个班级.

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.

在Serilog中是否有任何等效的方法可以给我记录程序?我知道有 ForContext() 选项,您可以指定您所在的类,但我仍然不知道如何在没有某种 logManager 的情况下获取记录器的实例.
PS
为每个类构造函数提供一个记录器作为参数(而不是使用 Getlogger())会花费一些时间,我真的希望避免使用此选项.

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.

推荐答案

在进行了一些研究之后,我发现在 NO Log4Net GetLogger()中存在等效项Serilog.

After I did some research, I founded out that there is NO Log4Net GetLogger() equivalent in Serilog.

这篇关于log4net方法GetLogger()在Serilog中等效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 09:19