Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log4Net: Rolling File appender, define extension

I want my logfile to look something like this: 2009-02-13.log

but the problem is that I can't seem to find any way to add the .log extension.

I've tried a lot of things but nothing helps. This is what I have this far:

<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">     <file value="Logs/Log4Net/.log"/>     <appendToFile value="true"/>     <rollingStyle value="Date"/>     <datePattern value="yyyy-MM-dd" />     <layout type="log4net.Layout.PatternLayout">       <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline"/>     </layout> </appender> 
like image 304
user29964 Avatar asked Mar 05 '09 14:03

user29964


People also ask

What is rolling file Appender in log4net?

RollingFileAppender means the system creates a log file based on your filters, this way you can have log files based on dates (one file each day), or get the file splitted into small chunks when it hits certain size.

Where is log4net configuration file?

You can configure the log4net. config file to create log files. The file is located in the webroot\App_data directory of the installation.

Where do log4net logs go?

In your case, the log file will be in bin\Debug\netcoreapp3.


1 Answers

The other answers escape the "g" in "log" since "g" is a special character in datePattern. This isn't wrong, but I prefer to wrap the entire set of non-date characters in single quotes, like so:

<datePattern value="yyyy-MM-dd'.log'" /> 

This gives the same results, but is easier for me to manage. This way, I don't have to recall which specific characters are special for datePattern (the list is long and varied). If I forget one character then I don't run the risk of borking my file names; they're all nicely escaped en masse.

like image 117
Craig Walker Avatar answered Sep 26 '22 03:09

Craig Walker