WorkerRole log4net Trace logs are not displayed in the output window

I have a number of Labor Role projects that I would like to use for the log4net function to log information. Unfortunately, none of my logs appear in my output window.

I go through the log line in the debugger, and the output window spits out the following line:

'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 Missing download symbols. The module is optimized and the debugger option "Only my code" is enabled.

Seeing that this is my code, I'm rather confused why I see this exception. The following are the settings for my log.config application:

<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 tried to follow the example in question , but the result was the same

+5
source share
2 answers

There are a few things you can check:

You call the log4net configuration before writing to the log file (once is enough):

 log4net.Config.XmlConfigurator(); 

The next thing to add is to add 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 clear the message immediately.

Make sure you configure Azure Diagnostics with all the debugging information.

You can then enable debugging of the internal debugging of log4net. See internal debugging on this log4net log page . The standard must be connected to your listener, which you configured. Add the autoflush = "true" parameter to the trace element. Or find a directory on a working role that you can write and access your journals.

+1
source

I was able to achieve.

Created Azure Service with a working role (target infrastructure: .NET Framework 4.5.2) and added the installed log4net version 2.0.7 to the working role.

The following section configuration has been added for log4net, as indicated in app.config.

 <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/> 

and log4net look like this.

 <log4net> <appender name="AzureTraceAppender" type="log4net.Appender.TraceAppender"> <layout type="log4net.Layout.PatternLayout"> <!-- can be any pattern you like --> <conversionPattern value="%logger - %message%newline"/> </layout> </appender> <!-- does not have to be at the root level --> <root> <level value="ALL"/> <appender-ref ref="AzureTraceAppender"/> </root> </log4net> 

So far, everything I have done is exactly the same as what you configured in your configuration file.

Configured log4net in the first line of the OnStart method WorkerRole.cs

 log4net.Config.XmlConfigurator.Configure(); 

Create a registrar for the working role as the next at the class level in WorkerRole.c

 private readonly ILog logger = LogManager.GetLogger("WorkerRole"); 

Trial logging information in OnStart, OnStop, Run, and RunAsync methods.

 //In OnStart logger.Info("From log4net : WorkerRole1 has been started"); //In OnStop logger.Info("From log4net : WorkerRole1 has stopped"); //In Run logger.Info("WorkerRole1 is running"); //In RunAsync logger.Info("From log4net : Working"); 

Running WorkerRole, pointing to a Development Storate account, displays the log entries in the output window as follows. To distinguish between entries recorded in Trace, I prefix entries using "From log4net:".

 WorkerRole: WorkerRole - From log4net : WorkerRole1 has been started WaWorkerHost.exe Information: 0 : From log4net : WorkerRole1 is running WorkerRole: WorkerRole - From log4net : Working 

enter image description here

I think the part that might not be in your code might be setting up log4net in OnStart . When I deleted the line log4net.Config.XmlConfigurator.Configure(); from the OnStart method, it stopped showing log4net entries in the output window.

-1
source

Source: https://habr.com/ru/post/1263797/


All Articles