特定のカテゴリに書き込むようにロガーに依頼することができます。
以下のサンプルは、AppOne、AppTwoという2つのカテゴリを作成しました。 次に、AppOneListener(AppOneカテゴリにバインドされている)とAppTwoListener(AppTwo Listenerにバインドされている)の2つのトレースリスナーを追加しました。
ログに記録する場合は、カテゴリを指定します。以下は
Logger.Write("test 1", "AppTwo");
構成です:categorySourcesセクションとリスナーセクションで ルック。
<loggingConfiguration name="" tracingEnabled="true" defaultCategory="AppOne">
<listeners>
<add name="AppOneListener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
fileName="traceAppOne.log" formatter="Text Formatter" />
<add name="AppTwoListener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
fileName="traceAppTwo.log" formatter="Text Formatter" />
</listeners>
<formatters>
<add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
template="Title:{title}{newline}
App Domain: {localAppDomain}{newline}
ProcessId: {localProcessId}{newline}
Process Name: {localProcessName}{newline}
"
name="Text Formatter" />
</formatters>
<categorySources>
<add switchValue="All" name="AppOne" />
<add switchValue="All" name="AppTwo">
<listeners>
<add name="AppTwoListener" />
</listeners>
</add>
</categorySources>
<specialSources>
<allEvents switchValue="All" name="All Events" />
<notProcessed switchValue="All" name="Unprocessed Category" />
<errors switchValue="All" name="Logging Errors & Warnings" />
</specialSources>
</loggingConfiguration>
申し訳ありませんが、私は非常に明確に説明していないと思います。フラットファイルとは異なる属性を持つイベントログリスナーを使用しています。 1人のリスナーだけが欲しい。現在、同じリンク設定ファイルを使用する31のアプリケーションがあります。私たちは、ソース名だけが異なる31のリスナーを持つことは望ましくありません。それは設定ファイルを大きくします(私たちにはたくさんのものがあります)。 –