2011-02-11 5 views
0

私はEnt Lib 5を使用しています。ソース属性が現在アプリケーションスイートの総称名に設定されているイベントログリスナがあります。実行時にリスナーのプロパティを変更します

この設定ファイルは、複数のプロジェクトとリンク/共有されています(長い話題で、変更されません)。

各アプリケーションは独自のソース名をイベントログに入れて一意に識別することができますが...実行時にソース名を変更するにはどうすればよいですか?

私は実際のログイベント自体について何でも簡単に変更できますが、各アプリケーションのリスナーソース属性を変更したいと思います。

うまくいけば、これは意味

UPDATEます:ここで を我々が使用しているコンフィグ設定では、それは私が実行時に変更したいSOURCE属性です...です。

名= "フォーマット済みのEventLog一般的な" タイプ= "Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener、Microsoft.Practices.EnterpriseLibrary.Logging、バージョン= 5.0.0.0、文化=中立、なPublicKeyToken = 31bf3856ad364e35" listenerDataTypeを追加= "Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData、Microsoft.Practices.EnterpriseLibrary.Logging、Version = 5.0.0.0、Culture = neutral、PublicKeyToken = 31bf3856ad364e35" formatter = "テキストフォーマッタ" traceOutputOptions = "None" filter = "すべて "machineName ="。 " source = "ランタイムに変更" log = "Application"

答えて

0

特定のカテゴリに書き込むようにロガーに依頼することができます。

以下のサンプルは、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}&#xA;App Domain: {localAppDomain}{newline}&#xA;ProcessId: {localProcessId}{newline}&#xA;Process Name: {localProcessName}{newline}&#xA;" 
       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 &amp; Warnings" /> 
     </specialSources> 
    </loggingConfiguration> 
+0

申し訳ありませんが、私は非常に明確に説明していないと思います。フラットファイルとは異なる属性を持つイベントログリスナーを使用しています。 1人のリスナーだけが欲しい。現在、同じリンク設定ファイルを使用する31のアプリケーションがあります。私たちは、ソース名だけが異なる31のリスナーを持つことは望ましくありません。それは設定ファイルを大きくします(私たちにはたくさんのものがあります)。 –

関連する問題