views:

136

answers:

2

I am using log4net and have completely setup it up with param name="File" value= "C:\Application.log". Yet the file is not created in C:. I am running Windows 7 and maybe something like permissions is preventing the file from being created.
Here is the app.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net" />
</configSections>

<log4net>
<root>
<level value="DEBUG" />
<appender-ref ref="LogFileAppender" />
</root>
<appender name="LogFileAppender“ type=“log4net.Appender.RollingFileAppender" >
<param name="File" value="C:\Users\Mohit\Documents\Application.log" />
<param name="AppendToFile" value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern“ value=“%-5p%d{yyyy-MM-dd hh:mm:ss} – %m%n" />
</layout>
</appender>
</log4net>
</configuration>

+1  A: 

Yeah, make sure the user that is executing the application has write permissions to c:.

Better yet, you probably don't want to write your application log to the root c:\ directory. It would probably be better to choose a location where your app is installed, or somewhere under Documents and Settings (or the Windows 7 equivalent).

Andy White
Also make sure that the appender is specified on the logger. It's easy to miss. If you are running the application in the debug mode under VS you can use a trace appender and the logging output will show up in the Output window, very useful if Log4Net itself says something.
Skurmedel
+3  A: 

You must provide a real file name. What you defined within your config is a folder name. Instead of:

<param name="File" value="C:\Users\Mohit\Documents" />

use something like:

<param name="File" value="C:\Users\Mohit\Documents\log.txt" />

Also, you'll probably need elevated permissions for your application to write the log to the root c: folder. UAC won't let you write to root folder.

Like Andy said, you'll be better to choose some subfolder of Windows Users folder like:

c:\Users\Mohit\AppData\Local\<MyApplication>

log4net has some predefined variables you can use to target special folders. There are some questions about that here on SO:

http://stackoverflow.com/questions/468989/how-to-specifiy-common-application-data-folder-for-log4net

http://stackoverflow.com/questions/964132/c-how-to-specify-the-appdata-file-path-in-the-app-config-file

Miroslav Popovic