CMS 10.10.4 with Relate logging not working

Vote:
 

I have a CMS 10.10.4 site that uses Relate (Community) where the logging is configured and the file is created but nothing is written to the file regardless of the logging level and even if I deliberately throw an error.

I have spun up a sample alloy tech site in version 10.0.1 and with no configuration the logging is working in this sample site as expected - it creates the file and logs to the file.

I've compared the config of the two sites to make sure they are the same and as far as I can tell they are.

The content of EPiServerLog.config is the same in both sites.

The Relate site that's not working does have a separate custom logging solution but I have commented this out in case it was causing conflicts and still not working.

The only difference in the Relate site config is that I have these entries in appSettings, if I comment these out then the files are not generated. Note these are not present in the alloy site which is working
    <!-- add these entries to configure log4net -->
    <add key="log4net.Config" value="EPiServerLog.config"/>
    <add key="log4net.Config.Watch" value="True"/>

Both sites are using version 2.1.0 of EPiServer.Logging.Log4Net

Alloy is using version 1.2.13 of log4net and the Relate site is using 1.2.10

I guess it could be the use of Relate?

Note: I can't upgrade the Relate site as it's using Relate and on premise Find

Any thoughts or suggestions greatly appreciated...

#319928
Apr 03, 2024 14:34
Vote:
 

Hi Mark

In order to troubleshoot log4net issue, you first need to enable the log4 internal debugging 

<appSettings>
    <add key="log4net.Internal.Debug" value="true"/>
</appSettings>

Once this has been enabled, you should be able to see log4net internal errors if there is any from console output (via Visual Studio output window) or alternatively you can configure Diagnostic trace in web.config to write errors to a txt file

<system.diagnostics>
      <trace autoflush="true">
          <listeners>
              <add 
                  name="textWriterTraceListener" 
                  type="System.Diagnostics.TextWriterTraceListener" 
                  initializeData="C:\source\temp\log4netinternal.txt" />
          </listeners>
      </trace>
</system.diagnostics>

If you don't see any errors, it means your log4net are configured correctly. The next step is to check your log4net appenders. Some of log4net appenders are using buffer, it won't write logs to file immediately until messages are reached to its buffer setting. If you want logs to be flushed on a specific log level without bothering buffer, you need to configure evaluator

<evaluator type="log4net.Core.LevelEvaluator">
  <threshold value="ERROR" />
</evaluator>

Last step, if you don't see any logs, you'll need to check if XmlConfigurator has been initiated anywhere in your application something like in global.ascx.cs (1st) or in startup.cs (2nd)

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

I hope above will help you work out the issue

#319984
Apr 04, 2024 3:46
Vote:
 

Thanks Vincent, that is really helpful.

I've tried your suggestions and I see the following in the trace file right at the end:

log4net:ERROR XmlConfigurator: Failed to find configuration section 'log4net' in the application's .config file. Check your .config file for the <log4net> and <configSections> elements. The configuration section should look like: <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />

So it looks like it's complaining it can't find the section named log4net and the associated <log4net> node in the web.config file of the Relate site but these don't exist in the Alloy site web.config file.

In the trace file it is finding the file EPiServerLog.config and it looks like it is using this to set up the logging. So it creates a new file if the existing file is not today's file etc.

So it seems like there is something in the web.config (?) that is trying to override and use the web.config rather than EPiServerLog.config? I can't spot anything obviously different between the sample Alloy site that works and the Relate site that doesn't work

More info from the trace file below so it creates and opens the expected appender, does a whole load of stuff then looks like it is trying to use the web.config file:

log4net: FileAppender: Opening file for writing [C:path to web app\App_Data\EPiServerErrors.log] append [True]
log4net: XmlHierarchyConfigurator: Created Appender [errorFileLogAppender]
log4net: XmlHierarchyConfigurator: Adding appender named [errorFileLogAppender] to logger [root].
log4net: XmlHierarchyConfigurator: Hierarchy Threshold []
log4net: DefaultRepositorySelector: Creating repository for assembly [NHibernate, Version=1.2.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4]
log4net: DefaultRepositorySelector: Assembly [NHibernate, Version=1.2.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4] Loaded From [C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\5878c60a\fbac7c5e\assembly\dl3\54773b8d\2bcf72dc_0a81da01\NHibernate.dll]
log4net: DefaultRepositorySelector: Assembly [NHibernate, Version=1.2.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4] does not have a RepositoryAttribute specified.
log4net: DefaultRepositorySelector: Assembly [NHibernate, Version=1.2.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4] using repository [log4net-default-repository] and repository type [log4net.Repository.Hierarchy.Hierarchy]
log4net: DefaultRepositorySelector: repository [log4net-default-repository] already exists, using repository type [log4net.Repository.Hierarchy.Hierarchy]
*** initialising conventions ***log4net: DefaultRepositorySelector: Creating repository for assembly [Web project name, Version=2.0.4.12, Culture=neutral, PublicKeyToken=null]
log4net: DefaultRepositorySelector: Assembly [Web project name, Version=2.0.4.12, Culture=neutral, PublicKeyToken=null] Loaded From [C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\5878c60a\fbac7c5e\assembly\dl3\0a11455b\35e5c279_ad86da01\Web project name.dll]
log4net: DefaultRepositorySelector: Assembly [Web project name, Version=2.0.4.12, Culture=neutral, PublicKeyToken=null] does not have a RepositoryAttribute specified.
log4net: DefaultRepositorySelector: Assembly [Web project name, Version=2.0.4.12, Culture=neutral, PublicKeyToken=null] using repository [log4net-default-repository] and repository type [log4net.Repository.Hierarchy.Hierarchy]
log4net: DefaultRepositorySelector: repository [log4net-default-repository] already exists, using repository type [log4net.Repository.Hierarchy.Hierarchy]
log4net: XmlConfigurator: configuring repository [log4net-default-repository] using .config file section
log4net: XmlConfigurator: Application config file is [C:path to web app\web.config]
log4net:ERROR XmlConfigurator: Failed to find configuration section 'log4net' in the application's .config file. Check your .config file for the <log4net> and <configSections> elements. The configuration section should look like: <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />

#320012
Edited, Apr 04, 2024 16:13
Vote:
 

Hi Mark

As the error suggested, try to add the missing configSections first to see if it is working

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

In addtion, are both project using the same version of log4net? From memory very long time ago, I encountered a logging issue with inccorect log4net version

I hope above helps

#320053
Apr 05, 2024 6:44
Vote:
 

Hi Vincent,

I have added both the <section name="log4net" and the <log4net> nodes. First I added an empty log4net node and still nothing written to the logs and then copied the config from the EPiServerLog.config into the log4net node. There are now no errors reported in the trace file. It's still weird it's using the EPiServerLog.config and then trying to get the config from the root web.config file as well.

On both occasions the trace informed that it was using the config in EPiServerLog.config and then web.config and it also infomed that it had opened the expected file for writing (for each config). Again nothing is written to the log file. Note I am throwing an exception in a controller to force an error which I would expect to be in the log file.

I checked the versions of log4net being used in the site that works and the site that doesn't and they were different. Updating the site that doesn't work to use the same version hasn't made any difference unfortunately.

#320056
Apr 05, 2024 9:54
Vote:
 

Just in case anyone else encounters this, it turned out I had to downgrade EPiServer.Logging.Log4Net from 2.1.0 to 1.1.0 to get the log files populated

#320225
Apr 09, 2024 16:21
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.