Have you verified that you're able to get the most basic configuration
up and running?
ConsoleAppender consoleAppender = new ConsoleAppender();
BasicConfigurator.Configure(consoleAppender);
ILog log = LogManager.GetLogger(typeof(Class1));
log.Debug("Hello");
log.Info("World");
The test cases are good place to look for example code:
http://tinyurl.com/k7psn
http://svn.apache.org/viewvc/logging/log4net/trunk/tests/src/Layout/
You're creating the appenders but you're not making the repository
aware of them. This may work:
// untested
Logger root = ((Hierarchy)LogManager.GetRepository()).Root;
root.AddAppender(fileAppenderTrace);
root.AddAppender(fileAppenderError);
That should simulate this part of the XML config file:
<root>
<appender-ref ref="FileAppenderTrace" />
<appender-ref ref="FileAppenderError" />
</root>
I'd recommend looking at the test to get a working configuration then
grow from there.
--- Brendan Long <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I am using log4net in a C# console application. The requirements
> specify that I retrieve the error log file and debug log file from
> the
> registry. Once I have done that I then need to configure my
> application
> to log to those files (for all classes).
>
> How do I do this? I can't find a configuration example for
> programmatic
> configuration, but it is mentioned in the documentation and examples
> as
> being possible. So far I have the following code. It seems to
> create
> the files, but nothing is ever logged to them.
>
> log4net.Appender.FileAppender fileAppenderTrace = new
> log4net.Appender.FileAppender();
> log4net.Appender.FileAppender fileAppenderError = new
> log4net.Appender.FileAppender();
> fileAppenderTrace.File = registry.getTracePath(); // Load debug
> log
> file from registry
> fileAppenderError.File = registry.getLogPath(); // Load
> main/error
> log file from registry
> log4net.Filter.LevelMatchFilter logFilter = new
> log4net.Filter.LevelMatchFilter();
> logFilter.LevelToMatch = log4net.Core.Level.Info;
> log4net.Filter.LevelMatchFilter traceFilter = new
> log4net.Filter.LevelMatchFilter();
> traceFilter.LevelToMatch = log4net.Core.Level.All;
> fileAppenderTrace.ClearFilters();
> fileAppenderTrace.AddFilter(traceFilter);
> fileAppenderError.ClearFilters();
> fileAppenderError.AddFilter(logFilter);
>
> How can I complete the configuration?
>
> Thanks,
> Brendan.
>
> This communication, including any attachments, is confidential. If
> you are not the intended recipient, you should not read it - please
> contact me immediately, destroy it, and do not copy or use any part
> of this communication or disclose anything about it. Thank you.
> Please note that this communication does not designate an information
> system for the purposes of the Electronic Transactions Act 2002.
>
>