5

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

Community
  • 1
  • 1
Nathan Tregillus
  • 6,006
  • 3
  • 52
  • 91
  • Where you are trying to see the logs? They won't be visible in Visual studio output window. You need to connect to the storage account and look in the table "WADLogsTable" – Chetan Feb 07 '17 at 04:24
  • per many blogs i have read, the traceappender should write to the output window when logging: http://interactivelogic.net/wp/2010/02/aspnet-logging-to-output-window-with-log4net/ – Nathan Tregillus Feb 07 '17 at 05:43
  • if this is not the correct log4net appender to use to write to the output log, let me know, I'll use anything. I want to make sure I am writing the correct stuff into the logs before I upload my project to azure – Nathan Tregillus Feb 07 '17 at 05:46
  • If you want the logs to be written to the output window then you need to disable the diagnostics configuration in the config file. You comment the entire section of and then try. – Chetan Feb 07 '17 at 07:11
  • *update* I gave up on log4net, and swapped to using the diagnostics framework. – Nathan Tregillus Apr 04 '17 at 21:26

1 Answers1

1

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.

Peter
  • 27,590
  • 8
  • 64
  • 84
  • Thanks peter, I'll try to use the ImmediateFlush to see if the output goes to the output window – Nathan Tregillus Feb 07 '17 at 23:24
  • I have added the XmlConfigurator to the assemblyinfo, and included the immediateFlush, but no dice, still does not work. I have removed log4net, and am now using the diagnostic tools directly, which is working. – Nathan Tregillus Feb 10 '17 at 17:18