1

EnterpriseLibrary.Logging は初めてです。web.config の loggingConfiguration の下には、次のフォーマッタがあります。

<formatters>
    <add name="Default Formatter" template="&#xA;Timestamp: {timestamp(local)}&#xA;&#xA;Message: {message}&#xA;&#xA;Category: {category}&#xA;&#xA;Priority: {priority}&#xA;&#xA;EventId: {eventid}&#xA;&#xA;Severity: {severity}&#xA;&#xA;Title:{title}&#xA;&#xA;Machine: {machine}&#xA;&#xA;Application Domain: {appDomain}&#xA;&#xA;Process Id: {processId}&#xA;&#xA;Process Name: {processName}&#xA;&#xA;Win32 Thread Id: {win32ThreadId}&#xA;&#xA;Thread Name: {threadName}&#xA;&#xA;User Name: {userName}&#xA;&#xA; extended Properties: {dictionary({key} - {value}&#xA;)}" 
             type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
    <add name="DBA Formatter" template="&#xA;Timestamp: {timestamp(local)}&#xA;&#xA;Message: {message}&#xA;&#xA;Category: {category}&#xA;&#xA;Priority: {priority}&#xA;&#xA;EventId: {eventid}&#xA;&#xA;Severity: {severity}&#xA;&#xA;Title:{title}&#xA;&#xA;Machine: {machine}&#xA;&#xA;Extended Properties: {dictionary({key} - {value}&#xA;)}" 
             type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</formatters>

コード ビハインドでは、メッセージを LogEntry に設定するだけです。タイムスタンプ、カテゴリ、優先度など、他のパラメータがどのように設定されるのか疑問に思います。ユーザー名を追加しましたが、機能しません。誰か私に光を当てることができますか?

4

1 に答える 1

3

これらのパラメーターに関する Microsoft の記事は次のとおり です。フォーマッタに挿入できるさまざまなトークンについて説明します。

「ユーザー名」は、事前定義されたトークンの 1 つではありません。しかし、(おそらく) LogEntry の ExtendedProperties プロパティを使用して回避できます。

 LogEntry le = new LogEntry();
 le.ExtendedProperties.Add("username", "jsmith");
于 2012-12-21T20:59:22.917 に答える