简体   繁体   中英

log4net with .NET Framework 4.6.2

I got my new Windows 10 having to install Visual Studio 2019 only with .NET Framework 4.6.2. I also all frameworks available available in the VS Installer including the framework 4.5.2, but cannot select it, so i have chosen 4.6.2 using my latest log4net package. But now it stopped creating my log file when using the application.

Looking at the "Supported Frameworks" page at Apache Log4Net it does not list 4.6 or 4.6.2. Does that mean its not supporting at all. Tried to clone the github repo compiling on my own but still, it is not creating my log file.

Any known issues with .NET 4.6.x?

Update with code: Globals.asax.cs contains this:

    protected void Application_Start(object sender, EventArgs e)
    {
        log4net.Config.XmlConfigurator.Configure();
        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
    }

web.config contains this:

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

and this:

 <log4net>
   <root>
    <level value="ALL"/>
    <appender-ref ref="file"/>
  </root>
  <appender name="file" type="log4net.Appender.RollingFileAppender">
   <encoding value="utf-8"/>
   <file value="log\LOG_"/>
   <appendToFile value="true"/>
   <rollingStyle value="Date"/>
   <maxSizeRollBackups value="5"/>
   <maximumFileSize value="15MB"/>
   <staticLogFileName value="false"/>
   <datePattern value="yyyy-MM-dd'.log'"/>
   <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%date [%thread] %level %logger - %message%newline"/>
   </layout>
 </appender>
</log4net>

and my cs files call this to log:

log4net.LogManager.GetLogger(HttpContext.Current.Session.SessionID).Debug(message);

Very strange. The Global.asax file was missing in the root directory. Since the Global.asax.cs is compiled into the DLL, i thought it runs anyway, but we need to keep Global.asax whose content simply is THIS:

<%@ Application Codebehind="Global.asax.cs" Inherits="MyNamespace.App.Global" Language="C#" %>

Without this, all the Application_Start having the.Configure() call for log4net is NOT called. Didn't know that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM