Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How I can set log4net to log my files into different folders each day?

Tags:

  1. I want to save all logs during each day in folder named YYYYMMdd - log4net should handle creating new folder depending on system datetime - how I can setup this?
  2. I want to save all logs during the day to n files of 1MB - I don't want to rewrite old files but to really have all logs during one day - how I can setup this?

I am usin C#

Regards Alex

like image 781
halex Avatar asked Mar 05 '10 09:03

halex


People also ask

Does log4net create directory?

Log4net watches for any new file created in the folder so simply creating the . log4net configuration file triggers the update within the component that is logging. When using a file appender, the destination folder does not have to exist. Log4net creates the folder.

How do I use multiple Appenders in log4net?

You can't log to separate appenders - you need to configure different loggers, and attach the appropriate appender to each one. Then log different messages to the different loggers.

Where do log4net logs go?

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


1 Answers

Try this (It should be OK!):

<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender">
  <file value="logs\\" />
  <appendToFile value="true" />
  <DatePattern value="yyyy\\\\MM\\\\dd'.inf.log'" />
  <rollingStyle value="Date" />
  <param name="StaticLogFileName" value="false" />
  <layout type="log4net.Layout.PatternLayout">
    <header value="[Header]&#13;&#10;" />
    <footer value="[Footer]&#13;&#10;" />
    <conversionPattern value="%date [%thread] %-5level %logger [%ndc] &lt;%property{auth}&gt; - %message%newline" />
  </layout>
</appender>

It will create a logfile named 'logs\2010\04\02.inf.log' (let date be 2010-04-02)

like image 150
he_king Avatar answered Jan 09 '23 03:01

he_king