設定で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">
<variable name="basePath" value="c:\logs\" />
<variable name="msgFormat" value="${message}" />
<targets async="true">
<target name="file"
xsi:type="File"
fileName="${basePath}/${logger}/${date:format=yyyy}/${date:format=MMMM}/log-${date:format=yyMMdd}-${level}.log"
layout="${msgFormat}"
concurrentWrites="true" />
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="file"/>
</rules>
</nlog>
次のコードを実行します。
var msg = "this is example string for logging test. it's not very long, but not very short";
var count = 20000;
Parallel.For(0, count, x => nlog.Info(msg));
NLog はファイルに書き込みますが、ファイル サイズが 1MB に達すると書き込みを停止します。単純なfor
ループを使用しようとしましたが、役に立ちませんでした。そして、内部ログを使用しようとしましたが、エラーはありません。ちなみに、次の文字列が表示されます。
2013-04-01 11:36:18.2458 トレース オープニング c:\logs/NLogTest/2013/April/log-130401-Info.log との concurrentWrite=False
これは非常に奇妙です。なぜなら、concurrentWritesのデフォルト値はでありtrue
、さらにこの値を config.