私はnLog 2.0を使用していますし、this interesting read後、私のようなシンプルなレイアウトに条件を適用しようとしました:nLog条件付きレイアウト
layout="${message:when=logger==A}"
layout="${message:when=logger=='A'}"
layout="${message:when='logger==A'}"
だけでなく、これらのどれもが任意の効果を持っていないん、彼らはまた、スローされません。エラーには条件が黙っ(throwExceptions
がtrueに設定されている)
- どのように動作するようにレイアウトを条件付きにするどこかに飲み込まれているようですので、?彼らも働いていますか?
- 何かが間違っている/認識されていない場合、nLogは例外をスローできますか?
これは完全なコードです。これは基本的なコンソールアプリケーションです。
main.cs:(実行ディレクトリにある)
class Program
{
static void Main(string[] args)
{
NLog.LogManager.GetLogger("A").Info("from A");
NLog.LogManager.GetLogger("B").Info("from B");
}
}
NLog.config:
<?xml version="1.0" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
throwExceptions="true">
<targets>
<target name="main" xsi:type="File" fileName="my.log"
deleteOldFileOnStartup="true" keepFileOpen="true"
layout="${callsite} ${message:when=logger=='A'}"/>
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="main" />
</rules>
</nlog>
出力:
ConsoleApplication1.Program.Main from A -> this should only log ${callsite}
ConsoleApplication1.Program.Main from B
完全なnlog設定を表示できますか? – kolbasov
@justipsが更新されました! – stijn