4

基本的に System.Diagnostics.TraceSource クラスから TraceEvent メソッドを呼び出す TraceManager クラスがあります。

TraceSource source = new TraceSource("MyTraceSource");
void TraceInternal(TraceEventType eventType, string message)
{
    if (source != null)
    {
        try
        {
            source.TraceEvent(eventType, (int)eventType, message);
        }
        catch (SecurityException)
        {
            //Cannot access to file listener or cannot have
            //privileges to write in event log
            //do not propagete this :-(
        }
    }
}

public void TraceError(string message)
{
    if (String.IsNullOrEmpty(message))
        throw new ArgumentNullException("message", Messages.exception_InvalidTraceMessage);

    TraceInternal(TraceEventType.Error, message);
}

そこで、エラーをトレースするために、TraceError メソッドを呼び出します。

さて、これは WebRole OnStart メソッドで使用するコードです。

DiagnosticMonitorConfiguration dmc = DiagnosticMonitor.GetDefaultInitialConfiguration();
TimeSpan transferPeriod = TimeSpan.FromMinutes(1.0);

dmc.Logs.ScheduledTransferPeriod = transferPeriod;
dmc.Logs.ScheduledTransferLogLevelFilter = LogLevel.Verbose;

DiagnosticMonitor.Start("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString", dmc);

これは私の web.config の構成です。

<system.diagnostics>
  <sources>
    <source name="MyTraceSource" switchName="sourceSwitch" switchType="System.Diagnostics.SourceSwitch">
      <listeners>
        <add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics">
          <filter type="" />
        </add>
      </listeners>
    </source>
  </sources>
  <switches>
    <add name="sourceSwitch" value="Verbose"/>
  </switches>
</system.diagnostics>

そして、これらは私の WebRole の構成設定です。

<ConfigurationSettings>
  <Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="DefaultEndpointsProtocol=https;AccountName=ValidAcountName;AccountKey=ValidAcountKey" />
</ConfigurationSettings>

最後に、ServiceDefinition に Diagnostics Import があります。

<Imports>
  <Import moduleName="Diagnostics" />
</Imports>

Azure Emulator の下で Visual Studio からアプリケーションを実行すると、正常に動作します。ログをストレージ エミュレーターまたはクラウド ストレージに保存するために ConfigurationSettings を変更することもできます。しかし、Azure にデプロイすると、ログが表示されません。

何か案は?

4

2 に答える 2

1

以下の設定が有効になっている場合、Azure プロジェクトのプロパティを確認していただけますか? 有効になっている場合は、無効にしてみてください。

ここに画像の説明を入力

参照: http://michaelcollier.wordpress.com/2012/04/02/where-is-my-windows-azure-diagnostics-data/

于 2012-05-30T18:03:49.677 に答える
0

TRACEアプリケーションをビルドするときに、定数を定義していることを確認しましたか? カスタム ビルド スクリプトがある場合、この定数が定義されていない可能性はありますか?

これにより、Trace ステートメントがログに記録されなくなります。

于 2015-07-16T15:29:20.360 に答える