logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nicko Cadell" <ni...@neoworks.com>
Subject RE: newbie - log4net deletes my config file!
Date Tue, 01 Nov 2005 22:15:04 GMT
Actually Visual Studio is deleting your config file.

Create a file called App.config in the root of your VisualStudio
project.
Visual Studio will automagically copy this file into the build output
directory and rename it to log4netConsoleTest.exe.config.
Put your log4net configuration in the App.config file.

As for not finding the file; When you call XmlConfigurator.Configure()
then log4net calls
System.Configuration.ConfigurationSettings.GetConfig("log4net"). If this
returns null then it prints out the message you are seeing. It does not
know where the file is or try to guess, it just asks the .NET
configuration API for its configuration. There are other ways of calling
XmlConfigurator.Configure(), for example passing a FileInfo param, which
will cause log4net to look for a specific file, then it will print out a
file not found message.

Cheers,
Nicko


> -----Original Message-----
> From: Erik_Brooks@idx.com [mailto:Erik_Brooks@idx.com] 
> Sent: 01 November 2005 20:48
> To: log4net-user@logging.apache.org
> Subject: newbie - log4net deletes my config file!
> 
> 
> I'm a .net and log4net newbie working thru the tutorial at 
> http://www.codeproject.com/csharp/log4net_intro.asp 
> 
> First example, logging to console with no config file, works 
> fine. 2nd example, using a small config file, I see two problems. 
> The main problem is that my config file is deleted from the 
> system when I run the project.  Here is the complete code of 
> the project: 
> using System;
> using log4net; 
> 
> namespace log4netConsoleTest
> { 
>         public class MainTestClass 
>         { 
>                 private static  ILog logger = 
> LogManager.GetLogger(typeof (MainTestClass)); 
> 
>         // constructor: 
>                 static MainTestClass () 
>                 { 
>                         log4net.Config.XmlConfigurator.Configure(); 
>                 } 
>                 
>                 static void Main(string[] args) 
>                 { 
>                         logger.Debug("Here is a debug log."); 
>                         logger.Error("... and a non-fatal error."); 
>                         logger.Fatal("... and a fatal error."); 
>                 } 
>         }
> } 
>   
> When I look into the file directory where the exe file lives, 
> I see that file "log4netConsoleTest.exe.config' exists. When 
> I run the project and stop at the 'LogManager.GetLogger' 
> line, and then look again into the file directory, the config 
> file is gone!   If I restore the file into the directory at 
> that time, then the logging works as expected. 
> 
> if I don't restore the file, log4net write this to the console: 
> "log4net:ERROR XmlConfigurator: Failed to find configuration 
> section 'log4net' in the application's .config file. Check 
> your .config file for the <log4net> and <configSections> 
> elements. The configuration section should look like: 
> <section name="log4net" 
> type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />" 
> I think that is also a problem. It apparently can't find the 
> file (cause it doesn't exist), but instead of saying 'file 
> not found', it says it can't find certain chars inside the 
> file.  I'd like the error message to include the fully 
> qualified name of where it looked for the file. 
> 
> All help appreciated,
> Erik Brooks
> 
> 
> -----------------------------------------------
> IMPORTANT NOTIFICATION
> -----------------------------------------------
> The contents of this e-mail and its attachments are 
> confidential and may be privileged. If you are not the 
> intended recipient of this e-mail, please notify IDX 
> immediately (by return e-mail to either the sender or 
> security@idx.com), destroy all copies of this message along 
> with any attachments and do not disclose, copy and/or 
> distribute the contents. The views expressed in this message 
> are those of the author and not necessarily those of IDX. In 
> the absence of a prior written agreement with you authorizing 
> commitments of IDX via e-mail, the above message shall not 
> bind IDX, unless from a duly authorized officer of the 
> company in a context indicating an intention to bind the company. 
> 
> This e-mail and its attachments are protected by copyright 
> and other laws. (c) IDX Systems Corporation 2005. All rights 
> reserved. IDX is a registered trademark of IDX Investment Corporation.
> 
> 

Mime
View raw message