Log4Net works fine in the local dev structure, the worker role also, but not the Web

I have a strange situation:

I have a custom log4net Appender configured to write to the Azure table storage. I have WorkerRole and WebRole. Both roles use osFamily = "3" (Windows Server 2012), I use .NET 4.5 in both cases and use ASP.NET MVC4 for WebRole. Everything is configured and works fine locally - both the work and web roles are registered correctly. However, when I deploy Azure, only Worker role logs work successfully, webrole does not create any logs (any!), Although it should be.

I configured log4net on WebRole to debug and send log4net debugging to Trace to check for some problems, but it doesn't send any errors / warnings. It also does not send log messages.

Here is the log generated by debugging log4net (shared sensitive data):

log4net: build log4net [log4net, version = 1.2.11.0, culture = neutral, PublicKeyToken = 669e0ddf0bb1aa2a]. Loaded from [D: \ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ Temporary ASP.NET Files \ root \ 59a01799 \ 5b6b1a2 \ build \ DL3 \ 8d97587f \ b9d49402_c202ce01 \ log4net.dll]. (.NET Runtime [4.0.30319.18010] on Microsoft Windows NT 6.2.9200.0) log4net: defaultRepositoryType [log4net.Repository.Hierarchy.Hierarchy] log4net: create a repository for the assembly [_my_referenced_assembly_, Version = 1.3.0.20282, Culture = neutral, PublicKeyToken = null] log4net: Assembly [_my_referenced_assembly_, Version = 1.3.0.20282, Culture = neutral, PublicKeyToken = null] Downloaded from [D: \ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ Temporary ASP.NET Files \ root \ 59a01799 \ 5b6b1a2 \ assembly \ DL3 \ 8cc98c20 \ 594c5b41_6f07ce01_my_referenced_assembly_.dll] log4net: Assembly [_my_referenced_assembly_, Version = 1.3.0.20282, Culture = neutral, PublicKeyToken = null] does not have an Attribute repository. log4net: Assembly [_my_referenced_assembly_, Version = 1.3.0.20282, Culture = neutral, PublicKeyToken = null] using the repository [log4net-default-repository] and repository type [log4net.Repository.Hierarchy.Hierarchy] log4net: Creating the repository [log4net-default -repository] using type [log4net.Repository.Hierarchy.Hierarchy] Loaded "Microsoft.WindowsAzure.ServiceRuntime, Version = 1.8.0.0, Culture = Neutral, PublicKeyToken = 31bf3856ad364e35" Getting "_some_setting_1_" from ServiceRuntime: PASS (_my_val1 Getting "_some_setting_2_" from ServiceRuntime: PASS (_my_value2_). Getting "_some_setting_3_" from ServiceRuntime: PASS (_my_value3_). Getting "Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" from ServiceRuntime: PASS (_my_conn_string_). Getting "_some_setting_4_" from ServiceRuntime: PASS (_my_value4_). log4net: assembly repository for assembly [_my_WEB_assembly_, Version = 1.3.0.20283, Culture = neutral, PublicKeyToken = null] log4net: Assembly [_my_WEB_assembly_, Version = 1.3.0.20283, Culture = neutral, PublicKeyToken = null] Downloaded from [D: \ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ Temporary ASP.NET Files \ root \ 59a01799 \ 5b6b1a2 \ assembly \ DL3 \ f695181f \ 98c73242_6f07ce01_my_WEB_assembly_.dll] log4net: Assembly [_my_WEB_assembly_, Version = 1.3.0.20 Culture = null] does not have an Attribute repository specified. log4net: Assembly [_my_WEB_assembly_, Version = 1.3.0.20283, Culture = neutral, PublicKeyToken = null] using the repository [log4net-default-repository] and repository type [log4net.Repository.Hierarchy.Hierarchy] log4net: repository [log4net-default- repository] already exists using the repository type [log4net.Repository.Hierarchy.Hierarchy] Getting "acs: idps" from ServiceRuntime: FAIL. Getting "acs: idps" from ConfigurationManager: PASS ([my_value]).

Here is an example of my app.config (for workers) and web.config (for web role) files (I also set this to WaIISHost.config just in case, but the result is the same - completely disabled WebRole):

<configuration> <configSections> <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" /> ... </configSections> ... <log4net> <appender name="AzureTableStoreAppender" type="_MyAssembly_.Logging.AzureTableStorageAppender, MyAssembly"> </appender> <root> <level value="ALL" /> <appender-ref ref="AzureTableStoreAppender" /> </root> </log4net> </configuration> 

I am configuring log4net through the assembly level attribute. Thus, in the assembly of the worker role, there are:

 [assembly: log4net.Config.XmlConfigurator(Watch = true)] 

And in the role on the Internet I have:

 [assembly: log4net.Config.XmlConfigurator(ConfigFile = "Web.config", Watch = true)] 

As I said, everything works fine and perfectly records table objects when running locally. My Local Environemtn is Windows 8 Pro that performs web roles on an IIS server (not IIS Express), which is IIS8. I also tried marking the WebRole executable to elevated , but still nothing happens. It looks like a black hole for log4net.

My custom appender is defined in a separate assembly .net Framework 4.5 (full), such as the Class Library, which is referenced in both Web projects and Worker. As already mentioned - on a local scale, everything is working fine. The build that defines my custom appender is definitely loaded, as it also contains the business logic of my web application, which also runs on Azure.

UPDATE

An interesting discovery. When I use the Debug configuration configuration, everything works everywhere (the azure web role also). But when I use the Release configuration (which is the default for packaging and production code), I cannot get log4net to work anywhere. This means that I cannot get Log4Net to work even locally using the Release config. No exceptions arise, errors are not logged. Oddly enough ...

+2
source share
2 answers

It turns out that the Release build is causing problems. In the question log section in log4net format, setting log4net through an assembly level attribute may differ in DEBUG and Release configurations.

In my setup, I used the static readonly property (the base controller) initialized during the declaration. This seemed to be a registrar configuration error. I moved my Logger instance property to the instance property my web application type and changed the controller property to return the Application property. Now everything works fine in all build configurations.

+1
source

As for Azure, I ran into the same issue. I came across this when nothing is registered in the Release configuration, even if both Debug and Release are working locally. My problem was not in the log4net configuration, but in its initialization.

I had this:

 private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); 

so I replaced it with the following line and this helped:

 private readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(WorkerRole)); 
0
source

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


All Articles