NLog记录器未记录到发布版本中已配置的日志文件中

问题描述 投票:1回答:1

我已经设置好配置文件

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
    </configSections>
    <nlog autoReload="true">
        <targets>
            <target name="file" type="File" fileName="${basedir}/log/${shortdate}.log" layout="${date:format=HH\:mm\:ss.fff}|${message}"/>
            <target name="file_webs" type="File" fileName="${basedir}/log/${shortdate}_webs.log" layout="${date:format=HH\:mm\:ss.fff}|${message}"/>
        </targets>
        <rules>
            <logger name="WebSocket.*" minlevel="Debug" writeTo="file_webs" final="true"/>
            <logger name="*" minlevel="Debug" writeTo="file" />
        </rules>
    </nlog>
</configuration>

记录器按如下方式加载到每个类中:

private static Logger logger = LogManager.GetCurrentClassLogger();

只要我不运行构建版本,日志就会定向到正确的文件。然后,所有日志记录都在默认日志文件中完成。可能是什么原因?

c# nlog
1个回答
1
投票
检查以下内容:

    是放置在发行版输出目录中的正确配置文件。可能那里的配置文件版本不同,或者丢失了。
  • 构建后还有其他东西在运行吗?像混淆源代码的工具一样?如果是这样,这可能会弄乱您的构建中的类名称,该配置将无法重定向到正确的输出。在这种情况下,可以通过以下方式显式加载类的记录器:
© www.soinside.com 2019 - 2024. All rights reserved.