Hi, I am totally new to Log4net. I have managed to get something going by adding a config file and simple logging I have hardcoded the value to be "c:\temp\log.txt" but this is not good enough
The logs must go to the special folders
path=Enviroment.GetFolderPath(Enviroment.SpecialFolder.CommonApplicationData;
and this path changes depending whether you are in windows Server 2008 or winxp or vista etc...
How can I just change the location of the file in log4net programmatically?
This is what I have done
<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:\temp\log.txt“ />
<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>
--
class Program
{
protected static readonly ILog log = LogManager.GetLogger(typeof(Program));
static void Main(string[] args)
{
log4net.Config.XmlConfigurator.Configure();
log.Warn(“Log something”);
path=Enviroment.GetFolderPath(Enviroment.SpecialFolder.CommonApplicationData;
//HOW CAN I CHANGE WHERE i LOG STUFF
}
}
Just need to figure out how I can change to log stuff to where i want to
Any suggestions? Thanks a lot