Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the directory of the Log4Net ILog instance

Tags:

c#-4.0

log4net

I have a dll, which gets an instance of ILog.

Using this ILog instance, i want to get the directory that the logger is writing to, because I want to create a file with some other info into the same folder.

I tried the following:

var fa = _log.Logger.Repository.GetAppenders().FirstOrDefault(a => a is RollingFileAppender);

For the fileappender, it does not have the fa.File option. The options that it shows me are: .DoAppend(), .Name and .Close()

Any ideas how to get the fa.File value? so that I can derive the directory and create my file in that directory?

like image 650
jaxxbo Avatar asked Dec 25 '22 17:12

jaxxbo


1 Answers

Figured it, based on a post here: https://stackoverflow.com/a/1343913/475882

I had to specify the type in <>:

var fa = _log.Logger.Repository.GetAppenders().OfType<RollingFileAppender>().FirstOrDefault();
like image 188
jaxxbo Avatar answered Jan 29 '23 13:01

jaxxbo