NLog不从XML配置加载规则

时间:2015-10-13 08:32:00

标签: c# logging nlog

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

<?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)

任何想法我做错了什么?

1 个答案:

答案 0 :(得分:2)

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

我很抱歉花了你的时间