Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the log filename through code?

How can I get the log filename in code? (So I can print it to the console)

My log file is define like this in app.config:

<appender name="RollingLogFileAppender"
   type="log4net.Appender.RollingFileAppender">
      <file value="logfile" />
    ...
like image 304
User Avatar asked Sep 25 '09 22:09

User


1 Answers

You look at your LogManager.GetAllRepositories. Inside the repositories you look at all the appenders in ILoggerRepository.GetAppenders. If the appender is of type RollingFileAppender you check its File property, or if you preffer you can check the appender by Name.

That being said it is very bad to do something like this in your code. What if the configuration is changed at deployment and the appender you expect is no longer present?

like image 88
Remus Rusanu Avatar answered Nov 07 '22 14:11

Remus Rusanu