Ok, so I’m understood how to configure the log4Net in my application, But now
First I want to improve the configuration by differencing the level of the logs if the application it’s a release or a debug, how can I do this?.
Second, If I had a folder in my project called LOG how can I set the configuration, to not used the physical folder of my application??
for example Instead of:
<file value="C:\physicalpath\LOG\Log.log" />
used
<file value="\LOG\Log.log" />
or
<file value="%some_variable%\LOG\Log.log" />
The documenation is straight forward:
So all you need to have is the full path like
C:\physicalpath\LOG\Log.logor the ralative one, this needs to start with the dot char.like.\App_Data\Log4Net.Logsyou can also use the folder name in the
fileattribute, then you must use thedatePatternattribute to specify the file name, for example:Also remember to add the
So you can avoid that
log4netlock the file and you can’t used it to append your messages.If you’re not used to
log4net, don’t forget to add the<root>node, this is the the one that let’slog4netknow what you want to use and not the<appender>nodes, for example, you can have 10<appender>nodes and use only one, the<root>node is then only configured with the one you want to use…here is a full configuration with 2 Mongo Appenders and 1 File Appender, the
<root>specifies that only the file appender is in use: