You haven't given any feedback if your program is finding its
App.config file correctly:

 <appSettings>
  <add key="log4net.Internal.Debug" value="true"/>
  <add key="Hello" value="World"/>
 </appSettings>

 Console.WriteLine(
  ConfigurationSettings.AppSettings["log4net.Internal.Debug"]);
 Console.WriteLine(
  ConfigurationSettings.AppSettings["Hello"]);

If you're running a WinForm program that doesn't have a console, you
can redirect output sent to the console with code like this:

 TextWriter consoleOutput = 
  new StreamWriter(@"c:\temp\consoleOut.txt");
 Console.SetOut(consoleOutput);
 Console.Write("Attempting to read value from appSettings: ");
 Console.Write(
  ConfigurationSettings.AppSettings["log4net.Internal.Debug"]);

If your log4net settings are stored in your App.config file and your
application cannot find the App.config file then log4net will not work.

Assuming your log4net node is in your App.Config file (along with
appropriate configSections node) all you need to do to configure
log4net is to call:

 log4net.Config.XmlConfigurator.Configure();

If you want to have a seperate log4net.config file and still have your
log4net.txt trace listener file to record log4net's internal messages,
you will need both an App.config and a log4net.config. The App.config
file is necessary for the appSettings and system.diagnostics nodes. The
log4net.config file is necessary for the log4net node.

--- Ramaa Davanagere <[EMAIL PROTECTED]> wrote:

>  
> 
> This is EXACTLY how my config file looks like
> 
>  
> 
> <?xml version="1.0" encoding="utf-8"?>
> 
> <configuration>
> 
>       <configSections>
> 
>             <section name="log4net"
> type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
> 
>       </configSections>
> 
>       <appSettings>
> 
>             <add key="log4net.Internal.Debug" value="true"/>
> 
>       </appSettings>
> 
>       <system.diagnostics>
> 
>             <trace autoflush="true">
> 
>                   <listeners>
> 
>                         <add name="textWriterTraceListener"
> type="System.Diagnostics.TextWriterTraceListener"
> initializeData="C:\\temp\\log4netIntDebug.txt"/>
> 
>                   </listeners>
> 
>             </trace>
> 
>       </system.diagnostics>
> 
>       <log4net>
> 
>             <appender name="FileAppender"
> type="log4net.Appender.FileAppender">
> 
>                   <file value="C:\\temp\\mylog.txt"/>
> 
>                   <appendToFile value="true"/>
> 
>                   <layout type="log4net.Layout.PatternLayout">
> 
>                         <conversionPattern value="%d %-5p %c %m%n"/>
> 
>                   </layout>
> 
>             </appender>
> 
>             <root>
> 
>                   <level value="ALL"/>
> 
>                   <appender-ref ref="FileAppender"/>
> 
>             </root>
> 
>       </log4net>
> 
> </configuration>
> 
>  
> 
>  
> 
> also, I changed my config filename to be "ItsMyAppConfigFile.config"
> 
>  
> 
> And also changed my code to this....
> 
>  
> 
> string strPath =
>
System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssem
> bly().Location);
> 
>                   log4net.Config.XmlConfigurator.Configure(new
> System.IO.FileInfo(strPath + "\\ItsMyAppConfigFile.config"));
> 
>  
> 
> What should I do next?

Reply via email to