【问题标题】:NLog doesn't load Rules from XML configurationNLog 不从 XML 配置加载规则
【发布时间】:2015-10-13 08:31:59
【问题描述】:

配置文件(变量除外)包含数据:

<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      autoReload="true"
      throwExceptions="false">

  <extensions>
    <add assembly="NLog.Extended" />
  </extensions>

  <targets async="True">
    <target name="TraceLogger"
            type="File"
            fileName="${TraceFullPath}"
            archiveFileName="${TraceArchiveFullPath}"
            maxArchiveFiles="100"
            archiveNumbering="Sequence"
            archiveEvery="None"
            layout="${message}" />
  </targets>

  <rules>
    <logger name="*"
            minLevel="Trace"
            writeTo="TraceLogger"
            enabled="True" />
  </rules>
</nlog>

测试执行代码为:

    var configuration = new XmlLoggingConfiguration(configurationPath);
    var factory = new LogFactory(configuration);
    var logger = factory.GetCurrentClassLogger();
    logger.Trace("Message");

调试器显示以下属性值:

configuration.base.LogginRules: Count = 0
configuration.base.AllTargets: Count = 0
logger.Is...Enabled = false (for all levels)

任何想法我做错了什么?

【问题讨论】:

  • 尝试将throwExceptions 设置为true。您的 .config 可能有问题。
  • 不幸的是,不是 :( 。我用谷歌搜索了 NLog 故障排除,并通过步骤找到了错误,记录器开始工作完美,即使我对变量和目标进行了更改

标签: c# logging nlog


【解决方案1】:

问题很简单:变量和目标值中区分大小写的拼写错误

很抱歉耽误您的时间

【讨论】:

    猜你喜欢
    • 2018-08-08
    • 1970-01-01
    • 1970-01-01
    • 2020-01-19
    • 1970-01-01
    • 2022-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多