NLog内部日志记录器的程序化配置

4

请问有人能帮忙编写 NLog 内部记录器的程序配置吗?

我有很多目标,但电子邮件目标没有发送任何电子邮件,尽管它具有日志记录规则。因此,我希望通过启用内部日志来获取更多信息。

但是,我进行了编程配置,并没有找到任何设置代码中的内部记录器的资源。

1个回答

6
一些示例:
// enable internal logging to the console
NLog.Common.InternalLogger.LogToConsole = true;

// enable internal logging to a file
NLog.Common.InternalLogger.LogFile = "c:\\log.txt";

// enable internal logging to a custom TextWriter
NLog.Common.InternalLogger.LogWriter = new StringWriter(); //e.g. TextWriter writer = File.CreateText("C:\\perl.txt")

 // set internal log level
NLog.Common.InternalLogger.LogLevel = LogLevel.Trace;

请参见 NLog wiki

可以通过在 InternalLogger 类上设置以下属性来配置内部日志记录:

  • InternalLogger.LogLevel - 指定内部日志记录级别
  • InternalLogger.LogFile - 指定日志文件的名称(null 将禁用日志记录到文件)
  • InternalLogger.LogToConsole - 启用或禁用日志记录到控制台
  • InternalLogger.LogToConsoleError - 启用或禁用日志记录到控制台错误流
  • InternalLogger.LogToTrace - 启用或禁用日志记录到 System.Diagnostics.Trace(在 NLog 4.3 中引入)
  • InternalLogger.LogWriter - 指定要用于日志记录的 TextWriter 对象
  • InternalLogger.IncludeTimestamp - 启用或禁用是否应在内部日志输出中包括时间戳(NLog 4.3+)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接