0

I use log4net and log4net.Async in my application to logs.It works good on my local environment(VS2017).When i release it and publish it to the IIS server,it works well at the starte time.But after i recycle the service,it can't write logs anymore,the log file is still there but has no log message inside.

I set the log folder whith permission(READ\WIRTE) for EVERYONE already.

there is my log config:

    <appender name="InfoRollingFileAppender" type="log4net.Appender.RollingFileAppender">
      <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />      
      <param name="Encoding" value="utf-8" />
      <param name="File" value="D:\Log\Info\" />
      <param name="AppendToFile" value="true" />
     <param name="rollingStyle" value="Date" />
      <param name="datePattern" value="yyyyMMdd\\yyyy-MM-dd-HH.'Info.log'" />

      <param name="staticLogFileName" value="false" />     
      <layout type="AsPay.GateWay.Log.AsRefundAccLayout">
        <conversionPattern value="--logtime:%date --:%-5level--msg:%Logtxt --:%CallType%newline" />
      </layout>    
      <filter type="log4net.Filter.LevelRangeFilter">
        <param name="LevelMin" value="INFO" />
        <param name="LevelMax" value="INFO" />
      </filter>

    </appender>
     <appender name="asyncForwarder" type="Log4Net.Async.AsyncForwardingAppender,Log4Net.Async">
      <appender-ref ref="InfoRollingFileAppender" />
    </appender>

    <root>
      <level value="DEBUG" />
      <appender-ref ref="asyncForwarder" />
    </root>
code in Global.asax:

    protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            System.IO.FileInfo fileinfo = new System.IO.FileInfo(Server.MapPath("~/log4net.Config"));
            log4net.Config.XmlConfigurator.Configure(fileinfo);
        }

The strange thing is after recycle the IIS,the log file(eg:2019-04-10-00.Info.log) is continued to be created,but there is no log content in the logfile.After recycle the IIS, There are no problems with the functionality of the service,except the log.

  • I try to track down log4net problems by set the config:[link](https://stackoverflow.com/a/756241/3168364) and i got the errorlog: log4net:ERROR [RollingFileAppender] ErrorCode: GenericFailure. AppenderSkeleton: No layout set for the appender named [InfoRollingFileAppender]. – user3168364 Apr 13 '19 at 03:06
  • The fundamental problem is:【log4net:ERROR Failed to find type [MyAccLayout]】.Finaly I solved the problem by the code:MyAccLayout a = new MyAccLayout(); before the : System.IO.FileInfo fileinfo = new System.IO.FileInfo(Server.MapPath("~/log4net.Config")); log4net.Config.XmlConfigurator.Configure(fileinfo); in the Global.asax – user3168364 Apr 13 '19 at 04:17

0 Answers0