简体   繁体   English

NLog LogManager.GetLogger(String,Type)重载的目的是什么

[英]What is the purpose of NLog LogManager.GetLogger(String, Type) overload

LogManager class has two methods: GetLogger and GetCurrentClassLogger , with an overload taking parameter Type loggerType LogManager类有两个方法: GetLoggerGetCurrentClassLogger ,带有一个重载参数Type loggerType

public static Logger GetLogger(string name, Type loggerType)
public static Logger GetCurrentClassLogger(Type loggerType)

Documentation states that loggerType is 'the type of the logger to create. 文档指出loggerType是'要创建的记录器的类型。 The type must inherit from NLog.Logger.' 该类型必须从NLog.Logger继承。

What is the purpose of such overloads? 这种超载的目的是什么? Why may I need to create loggers of inherited types? 为什么我需要创建继承类型的记录器?

You might create your own Logger as a subclass of the NLog Logger if you want to add some specific behavior to your Logger. 如果要向Logger添加某些特定行为,可以创建自己的Logger作为NLog Logger的子类。

If you look at NLog's github repository here: 如果你在这里查看NLog的github存储库:

https://github.com/NLog/NLog/tree/master/examples/ExtendingLoggers/InheritFromLogger https://github.com/NLog/NLog/tree/master/examples/ExtendingLoggers/InheritFromLogger

You can see an example of how to extend NLog by subclassing Logger. 您可以通过继承Logger来查看如何扩展NLog的示例。 In the case of the example, the new subclassed Logger (LoggerWithEventID) makes it easy to tag every logging statement with an "event ID". 在示例的情况下,新的子类Logger(LoggerWithEventID)可以很容易地使用“事件ID”标记每个日志记录语句。 There are other ways to tag each statement with an event ID that don't involve subclassing, but this just shows that it is possible to implement such a thing. 还有其他方法可以使用不涉及子类化的事件ID来标记每个语句,但这只是表明可以实现这样的事情。

These overloads allow a developer to develop his/her own custom Logger implementation and then have NLog create and dispense those custom Loggers without going through a lot of effort. 这些重载允许开发人员开发他/她自己的自定义Logger实现,然后让NLog创建并分配这些自定义Logger而无需花费很多精力。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 LogManager.GetLogger(“ Name”)和LogManager.GetCurrentClassLogger()有什么区别? - What is difference between LogManager.GetLogger(“Name”) and LogManager.GetCurrentClassLogger()? LogManager.GetLogger和xmlconfigurator.configure序列 - LogManager.GetLogger and xmlconfigurator.configure sequence 在自定义TraceListener中使用log4net的LogManager.GetLogger()会引发NullReferenceException - log4net's LogManager.GetLogger() throws NullReferenceException when used in custom TraceListener 使用 NLog GetLogger 切换回默认记录器 - Using NLog GetLogger To Switch Back To Default Logger 如何使用Unity为LogManager(NLog)获取命名记录器 - How to get named loggers for LogManager (NLog) with Unity 什么是 GetFullPath(String, String) 重载? - What is the GetFullPath(String, String) overload? LogManager.Configuration.FindRuleByName 返回 null。 日志 - LogManager.Configuration.FindRuleByName return null. NLog NLog 没有使用 LogManager.GetCurrentClassLogger 中派生最多的类 - NLog is not using the most derivated class in LogManager.GetCurrentClassLogger 得到错误20'NLog.LogManager'不包含'GetCurrentClassLogger'的定义 - Getting Error 20 'NLog.LogManager' does not contain a definition for 'GetCurrentClassLogger' ServiceBase.OnStop 期间的 NLog LogManager.LogFactory.Flush - NLog LogManager.LogFactory.Flush during ServiceBase.OnStop
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM