In log4net, we can use the FileAppender to log information into text files. There are two ways to specify the file:
1. Specify the file name in absolutely path. For example:
2. Specify the file name in relative path. For example:
1. Specify the file name in absolutely path. For example:
<log4net>
<appender name="FileAppender" type="log4net.Appender.FileAppender">
<file value="c:\logs\log-file.txt" />
<appendToFile value="true" />
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
</layout>
</appender>
</log4net>
Obviously, the file will be created in c:\logs\log-file.txt2. Specify the file name in relative path. For example:
<log4net>
<appender name="FileAppender" type="log4net.Appender.FileAppender">
<file value="logs\log-file.txt" />
<appendToFile value="true" />
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
</layout>
</appender>
</log4net>
In web application, the file will be created at the <web site root folder>/logs/log-file.txt. You have to make sure you created the file first and the application pool user has the Modify permission on the file.
Comments