简体   繁体   English

NLog 内部记录器的编程配置

[英]Programmatic configuration of NLog internal logger

Can anyone please help with programmatic configuration of NLog internal logger?任何人都可以帮助 NLog 内部记录器的编程配置吗?

I have various targets and the email target is not sending any email, although it does have the logging rule.我有各种目标,电子邮件目标没有发送任何电子邮件,尽管它确实有日志记录规则。 So I was hoping to get more insight by enabling the internal log.所以我希望通过启用内部日志来获得更多的洞察力。

However I do programmatic configuration and did not find any resource that sets up the internal logger in code.但是我进行了编程配置,并没有找到任何在代码中设置内部记录器的资源。

Soms examples: Soms 示例:

// 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;

See the NLog wiki请参阅NLog 维基

Internal logging can be configured through code by setting the following properties on InternalLogger class:通过在 InternalLogger 类上设置以下属性,可以通过代码配置内部日志记录:

  • InternalLogger.LogLevel - specifies internal logging level InternalLogger.LogLevel - 指定内部日志记录级别
  • InternalLogger.LogFile - specifies name of the log file (null will disable logging to a file) InternalLogger.LogFile - 指定日志文件的名称(null 将禁用记录到文件)
  • InternalLogger.LogToConsole - enables or disables logging to the console InternalLogger.LogToConsole - 启用或禁用记录到控制台
  • InternalLogger.LogToConsoleError - enables or disables logging to the console error stream InternalLogger.LogToConsoleError - 启用或禁用记录到控制台错误流
  • InternalLogger.LogToTrace - enables or disables logging to System.Diagnostics.Trace (introduced in NLog 4.3) InternalLogger.LogToTrace - 启用或禁用日志记录到 System.Diagnostics.Trace(在 NLog 4.3 中引入)
  • InternalLogger.LogWriter - specifies a TextWriter object to use for logging InternalLogger.LogWriter - 指定用于日志记录的 TextWriter 对象
  • InternalLogger.IncludeTimestamp - enables or disables whether timestamps should be included in the internal log output (NLog 4.3+) InternalLogger.IncludeTimestamp - 启用或禁用时间戳是否应包含在内部日志输出中(NLog 4.3+)

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM