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

NLog - Having Performance issues and logs are always writing to one file rather than multiple file

我的 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 drastically.But 在某处读到我们还需要设置 openFileCacheTimeout 以使性能乐观。这是真的?或者如果两者都设置了它会破坏性能吗?
  2. 不按照规则将日志写入多个文件 - 但不工作,因为 expected.All 日志写入 MyApplicationHandlerMetrics
  3. 归档工作如预期 - "No issues I am facing at the moment"
  4. 如果我的系统处理 140 messages/second
  5. 时可以提出任何改进性能的建议,将不胜感激

谢谢, 维诺德

  1. 性能问题。是的,使用 KeepFileOpen=true 性能会更好。 openFileCacheTimeout 将帮助早于 4.4.2 的 NLog 版本从文件问题中恢复。使用 10 分钟的超时,不会影响性能。
  2. 很确定这是你这边的问题,而不是 NLog 中的问题。你检查过 Internal Log 了吗?也许从一个有效的简单配置开始,然后从那里扩展?
  3. 很好
  4. 嗯,NLog 版本。当使用 SSD 磁盘时,4.4.2 可以处理超过 200.000 messsages/second。