How to output trancelog and EventLog to storage on windowsazure
1. modify web. config to enable a diagnostic listener.
<configuration> <system.diagnostics> <trace> <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> </trace> </system.diagnostics></configuration>
2. Start the diagnostic listener in the onstart function.
Public override bool onstart () {diagnosticmonitorconfiguration diagconfig = diagnosticmonitor. getdefaultinitialconfiguration (); // trance log diagconfig. logs. scheduledtransferloglevelfilter = loglevel. verbose; diagconfig. logs. scheduledtransferperiod = system. timespan. fromminutes (1); // EventLog diagconfig. windowseventlog. datasources. add ("system! * "); Diagconfig. windowseventlog. CES. Add (" application! * "); Diagconfig. windowseventlog. scheduledtransferloglevelfilter = loglevel. verbose; diagconfig. windowseventlog. scheduledtransferperiod = system. timespan. fromminutes (1); // Microsoft. windowsazure. plugins. diagnostics. connectionstring is required in. the storage connection string diagnosticmonitor configured in the cscfg file. start ("Microsoft. windowsazure. plugins. diagnostics. connectionstring ", diagconfig); Return base. onstart ();}
3. Output trancelog and EventLog in other code.
// Output a trancelog to the storage trace. writeline ("writetasklist... "); // output two eventlogs to the storage: EventLog eventapp2 = new EventLog (" application "); eventapp2.source =" azuretest app "; eventapp2.writeentry (count +" EventLog write (azuretest APP) "); EventLog eventsys2 = new EventLog (" system "); eventsys2.source =" azuretest sys "; eventsys2.writeentry (count +" EventLog write (azuretest sys )");
Reference: cloud diagnosis: control logging and tracking in Windows azure