P
Patrick
I haven't used log4Net for a while, and couldn't figure out how to use the
Appender!
I have my App.config set as stated at the end of this post
Within the code, I did the following, but when I actually do logging like
log.Info("Application [testApp] Start"); (I only get the log message in the
Console window, and not in the file c:\log-file.txt as specified). the code
is executed as a console application by someone logged on as a local
Administrator on Windows XP Professional SP1, .NET framework 1.1
How could I get the Appender working??
------------------------------Start of Code
snippet------------------------------
// Create a logger for use in this class
private static readonly log4net.ILog log =
log4net.LogManager.GetLogger(typeof(LoggingExample));
/// <summary>
/// Static constructor used to initialise the logging before
/// the main class loads, i.e. before the Main() method is called.
/// </summary>
static LoggingExample()
{
// If using the following line, I get an error in console saying
// log4net:ERROR No appender named [FileAppender] could be found.
// log4net:ERROR No appender named [EventLogAppender] could be found.
//
//log4net.Config.DOMConfigurator.Configure();
log4net.Config.BasicConfigurator.Configure();
}
------------------------------End of Code
snippet------------------------------
------------------------------Start of
App.config------------------------------
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<log4net>
<root>
<appender-ref ref="FileAppender" />
<appender-ref ref="EventLogAppender" />
<applicationName value="MyApp" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%ndc] -
%message%newline" />
</layout>
</appender>
<appender name="FileAppender" type="log4net.Appender.FileAppender">
<file value="c:\\log-file.txt" />
<appendToFile value="true" />
<encoding value="unicodeFFFE" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%ndc] -
%message%newline" />
</layout>
</appender>
</log4net>
</configuration>
------------------------------End of
App.config------------------------------
Appender!
I have my App.config set as stated at the end of this post
Within the code, I did the following, but when I actually do logging like
log.Info("Application [testApp] Start"); (I only get the log message in the
Console window, and not in the file c:\log-file.txt as specified). the code
is executed as a console application by someone logged on as a local
Administrator on Windows XP Professional SP1, .NET framework 1.1
How could I get the Appender working??
------------------------------Start of Code
snippet------------------------------
// Create a logger for use in this class
private static readonly log4net.ILog log =
log4net.LogManager.GetLogger(typeof(LoggingExample));
/// <summary>
/// Static constructor used to initialise the logging before
/// the main class loads, i.e. before the Main() method is called.
/// </summary>
static LoggingExample()
{
// If using the following line, I get an error in console saying
// log4net:ERROR No appender named [FileAppender] could be found.
// log4net:ERROR No appender named [EventLogAppender] could be found.
//
//log4net.Config.DOMConfigurator.Configure();
log4net.Config.BasicConfigurator.Configure();
}
------------------------------End of Code
snippet------------------------------
------------------------------Start of
App.config------------------------------
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<log4net>
<root>
<appender-ref ref="FileAppender" />
<appender-ref ref="EventLogAppender" />
<applicationName value="MyApp" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%ndc] -
%message%newline" />
</layout>
</appender>
<appender name="FileAppender" type="log4net.Appender.FileAppender">
<file value="c:\\log-file.txt" />
<appendToFile value="true" />
<encoding value="unicodeFFFE" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%ndc] -
%message%newline" />
</layout>
</appender>
</log4net>
</configuration>
------------------------------End of
App.config------------------------------