简体   繁体   English

使用 .NET Framework 4.6.2 的 log4net

[英]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.我的新 Windows 10 必须仅安装 .NET Framework 4.6.2 的 Visual Studio 2019。 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.我还在 VS 安装程序中提供了所有可用的框架,包括框架 4.5.2,但无法选择它,所以我选择了 4.6.2 使用我最新的 log4net 包。 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.查看 Apache Log4Net 的“支持的框架”页面,它没有列出 4.6 或 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.试图克隆我自己编译的 github 存储库,但它仍然没有创建我的日志文件。

Any known issues with .NET 4.6.x? .NET 4.6.x 有任何已知问题吗?

Update with code: Globals.asax.cs contains this:使用代码更新:Globals.asax.cs 包含以下内容:

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

web.config contains this: web.config 包含这个:

  <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:我的 cs 文件调用它来记录:

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

Very strange.很奇怪。 The Global.asax file was missing in the root directory.根目录中缺少 Global.asax 文件。 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:由于 Global.asax.cs 被编译到 DLL 中,我认为它无论如何都会运行,但我们需要保留 Global.asax,其内容只是这样:

<%@ 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.没有这个,所有具有 .Configure() 调用 log4net 的 Application_Start 都不会被调用。 Didn't know that.不知道。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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