MVC アプリケーションの場合、initializeData="CustomWeblog.txt" パラメーターが使用されている場合、カスタム リスナーはログ ファイルを作成しませんが、initializeData="d:\CustomWeblog.txt" はファイルの作成をトリガーします。そのような行動の理由は何ですか?コンソール アプリケーションは、すべてのタイプのリスナーのファイルを生成します。
カスタムクラス:
public class CustomTextWriterTraceListener : TextWriterTraceListener
{
public CustomTextWriterTraceListener(string fileName) : base(fileName)
}
Web.config (mvc アプリケーション、web.config)
<trace autoflush="true" />
<sources>
<source name="Trace">
<listeners>
<add name="TextWriterListner"
type="System.Diagnostics.TextWriterTraceListener, WebTracing" initializeData="Weblog.txt"/>
<!-- the file is created -->
<add name="CustomTextWriterListner"
type="WebTracing.CustomTextWriterTraceListener, WebTracing" initializeData="CustomWeblog.txt"/>
<!-- the file is not created in MVC application ?! -->
<add name="CustomTextWriterListnerAbsolutePath"
type="WebTracing.CustomTextWriterTraceListener, WebTracing" initializeData="d:\CustomWeblog.txt"/>
<!-- the file is created -->
</listeners>
</source>
</sources>
カスタム リスナーはログ ファイルを作成しません。
発信者:
TraceSource obj = new TraceSource("Trace", SourceLevels.All);
obj.TraceEvent(TraceEventType.Critical,0,"This is a critical message");
このブログとこのブログから、いくつかの追加構成を追加しようとしました。しかし、成功はありません。絶対パスを指定する必要がありますか? カスタム リスナー用に別のアセンブリを作成することによる回避策はありますか?