NLog - 性能问题和日志总是写入一个文件而不是多个文件

时间:2017-03-03 02:37:24

标签: nlog

我的nlog配置如下

<?xml version="1.0" encoding="UTF-8"?>
<nlog throwExceptions="true">
    <targets>
        <target name="file" type="AsyncWrapper" queueLimit="5000" overflowAction="Discard">
            <target type="BufferingWrapper" name="file" bufferSize="120">
                <target type="File" fileName="${basedir}/logs/MyApplicationLog.log" layout="${longdate} ${exception:format=tostring} ${message} ${newline}" archiveFileName="${basedir}/archives/MyApplicationLogArchive/MyApplicationLog_{##}.log" archiveEvery="Day" archiveNumbering="Rolling" maxArchiveFiles="7" keepFileOpen="true" openFileCacheTimeout="30" />
            </target>
        </target>
        <target name="MyApplicationHandlerLog" type="AsyncWrapper" queueLimit="5000" overflowAction="Discard">
            <target type="BufferingWrapper" name="file" bufferSize="120">
                <target type="File" fileName="${basedir}/logs/MyApplicationHandlerLog.log" layout="${longdate} ${exception:format=tostring} ${message} ${newline}" archiveFileName="${basedir}/archives/MyApplicationHandlerLogArchive/MyApplicationHandlerLog_{##}.log" archiveEvery="Day" archiveNumbering="Rolling" maxArchiveFiles="7" keepFileOpen="true" openFileCacheTimeout="30" />
            </target>
        </target>
        <target name="MyApplicationHandlerMetrics" type="AsyncWrapper" queueLimit="5000" overflowAction="Discard">
            <target type="BufferingWrapper" name="file" bufferSize="120">
                <target type="File" fileName="${basedir}/logs/MyApplicationHandlerMetrics.log" layout="${longdate} ${exception:format=tostring} ${message} ${newline}" archiveFileName="${basedir}/archives/MyApplicationHandlerMetricsArchive/MyApplicationHandlerMetrics_{##}.log" archiveEvery="Day" archiveNumbering="Rolling" maxArchiveFiles="7" keepFileOpen="true" openFileCacheTimeout="30" />
            </target>
        </target>
    </targets>
    <rules>
        <logger name="*" minlevel="Info" writeTo="file" />
        <logger name="MyApplicationHandlerLog" minlevel="Info" writeTo="MyApplicationHandlerLog" />
        <logger name="MyApplicationHandlerMetrics" minlevel="Info" writeTo="MyApplicationHandlerMetrics" />
    </rules>
</nlog>   

我面临以下列出的多个问题 - 需要您的帮助才能对其进行排序。

  1. 性能问题 - 我已经在目标中启用了KeepFileOpen,大大提高了性能。但是我们需要设置openFileCacheTimeout,以使性能更加乐观。这是真的?如果两者都设定了会不会影响性能?
  2. 不按规则将日志写入多个文件 - 但未按预期工作。所有日志都写入MyApplicationHandlerMetrics
  3. 存档按预期工作 - “我目前没有遇到任何问题”
  4. 非常感谢如果有任何建议可以改善效果,因为我的系统处理140条消息/秒
  5. 谢谢, 维诺德

1 个答案:

答案 0 :(得分:1)

  1. 性能问题。使用KeepFileOpen = true可以提高性能。 openFileCacheTimeout将帮助早于4.4.2的NLog版本从文件问题中恢复。使用10分钟的超时时间并且不会出现性能损失。
  2. 非常确定这是你的问题,而不是NLog中的问题。你检查过Internal Log了吗?也许从一个有效的简单配置开始,并从那里扩展?
  3. NLog版本。当使用SSD磁盘时,4.4.2可以处理超过200,000次/秒的消息。
相关问题