logging - 如何使用nlog写入关键级别的事件日志?

标签 logging event-log nlog

我正在尝试将日志从 nlog 写入窗口的事件日志。这是我的配置

<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
    <targets>                
        <target name="eventLog" xsi:type="EventLog" layout="${longdate} [${level:upperCase=true}] : ${message} ${exception:format=ToString}" log="Application" source="mySource"/>
    </targets>
    <rules>
        <logger name="*" minlevel="Debug" writeTo="eventLog"/>
    </rules>
</nlog>

我需要按级别区分事件日志中的日志,我需要有单独的 ErrorCritical 级别日志 但那些行:

logger.Error("error test do eventLogu");
logger.Fatal("fatal test do eventLogu");

均以错误级别写入事件日志。

是否可以使用nlog写入Critical级别的日志?

最佳答案

看起来不像。

如果我的理解是正确的,EventLogTarget 使用 EventLogEntryType Enumeration选择事件日志级别。此枚举没有关键值,该值用于较低级别(内核等)事件。

NLog Code它自己说

else if (logEvent.Level >= LogLevel.Error)
{
    entryType = EventLogEntryType.Error;
}

关于logging - 如何使用nlog写入关键级别的事件日志?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11541010/

相关文章:

android - 从类中收集所有 Log.d 并将其保存到 SDCard

c# - 设计应用程序范围的日志记录系统的准则是什么?

c# - 应用程序日志架构

c# - 使用NLog获取Application_Start()中的错误并重定向到友好页面错误

javascript - 如何使用 Winston 库在 Node.js 中每天将日志分离到单独的文件中

c++ - Boost::Log - 使用严重性和自定义过滤器属性记录?使用哪个宏?

c# - 在安装 .Net 服务期间创建自定义事件日志和事件源的最可靠方法是什么

azure - 是否可以将 Windows 事件日志获取到应用程序洞察中?

xpath - Xpath查询以进行事件过滤

c# - 如何正确从 appsettings.json 中提取 NLog DB ConnectionString