Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WorkerRole log4net Trace appender logs not appearing in output window

I have a number of Worker Role projects that I would like to utilize the log4net functionality to log the information. unfortunately none of my logs are actually appearing in my output window.

I step over a log line in the debugger, and the output window spits out the following line instead:

'WaWorkerHost.exe' (CLR v4.0.30319: RdRuntime): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.Caching\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Runtime.Caching.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.

Seeing as this is my code, I am pretty confused why i am seeing this exception. below is my logging app.config settings:

 <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <section name="Montetary.Agents.HappyBirthday.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    </sectionGroup>
  </configSections>
  <system.diagnostics>
    <trace>
      <listeners>
        <add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=2.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics">
          <filter type="" />
        </add>
      </listeners>
    </trace>
  </system.diagnostics>
  <log4net>
    <appender name="AzureTraceAppender" type="log4net.Appender.TraceAppender">
      <layout type="log4net.Layout.PatternLayout">
        <!-- can be any pattern you like -->
        <conversionPattern value="%logger - %message" />
      </layout>
    </appender>
    <!-- does not have to be at the root level -->
    <root>
      <level value="ALL" />
      <appender-ref ref="AzureTraceAppender" />
    </root>
  </log4net>

I attempted to follow the example in this question, but the result was the same

like image 871
Nathan Tregillus Avatar asked Nov 08 '22 02:11

Nathan Tregillus


1 Answers

There are some things you can check:

Do you call log4net configure before you write to you log file (only once is enough):

log4net.Config.XmlConfigurator();

The next thing is to add flushing to your configuration:

<appender name="AzureTraceAppender" type="log4net.Appender.TraceAppender">
  <param name="ImmediateFlush" value="true" />
  <layout type="log4net.Layout.PatternLayout">
    <!-- can be any pattern you like -->
    <conversionPattern value="%logger - %message" />
  </layout>
</appender>

This will flush the message immediately.

Be sure you have configurated Azure Diagnostics to all information for debugging.

Then you can enable debugging internal log4net debugging. See internal debugging on this log4net faq page. Standard it should log to your listener you have configured. Add the autoflush="true" option to the trace element. Or find directory on the worker role you can write to and access to read your logs.

like image 138
Peter Avatar answered Dec 06 '22 04:12

Peter