4

I am using log4net in .net core 2.0 app as below:

Startup File:

using Microsoft.Extensions.Logging;

public class Startup
{
    public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
    {
        loggerFactory.AddLog4Net();         
    }       
 }

log4net.config

<?xml version="1.0" encoding="utf-8" ?>
<log4net>
  <appender name="RollingFile" type="log4net.Appender.FileAppender">
    <file value="C:\Logs\app.log" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%-5p %d{hh:mm:ss} %message%newline" />
    </layout>
  </appender>
  <root>
<level value="ALL" />
<appender-ref ref="RollingFile" />
  </root>
</log4net>

Controller writing log:

 public class MyController : Controller
 {
    private static readonly log4net.ILog log =
      log4net.LogManager.GetLogger(typeof(MyController));


        [HttpGet("api/value")]
        public IEnumerable<string> Get()
       {
            log.Debug("logging entry");
            return new string[] { "from api..." };
        }    
 }

The above works but its just creating one file. I want it to create daily files, like appname+todaysdays.log. How can we do that.

I tried adding:

<param name="DatePattern" value="dd.MM.yyyy'.log'" />
<staticLogFileName value="false" />

But still does not create the file with date.

kaka1234
  • 770
  • 3
  • 9
  • 30

0 Answers0