The Log4Net mailing list is a great source of information about using log4Net, in this forum we collect all the messages in the log4net user list and some selected threads from the developer list.
| Author |
Messages |
|
Gourlay, Colin
 |
| 10/16/2008 3:28 PM |
|
Hello.
I am trying to retrieve the connection string within my logging.config (a separate file outside the web.config in case that is significant) file.
I am using the code below but it seems to use a default(?) logger which is not defined in my config file (a TextWriterAppender).
I am wondering if this is occurring because the config file cant be located or the code I am using is just wrong.
Pointers/Tips/Advice very much appreciated.
internal static string LoggerConnectionString
{
get
{
// determine the logging hierarchy
Hierarchy log4netHierarchy = LogManager.GetRepository() as Hierarchy;
// magic number used because there should only ever be one appender defined in this application
// the appender variable evaluates to null!
AdoNetAppender appender = log4netHierarchy.Root.AppendersΎ] as AdoNetAppender;
// return connection string if it is found
return appender.ConnectionString ?? string.Empty;
}
}
Edinburgh Business School is a Charity Registered in Scotland, SC026900
|
|
|
|
|
Dag Christensen
 |
| 10/16/2008 3:57 PM |
|
Shouldn't be a TextWriterAppender there. Can you post your configuration file?
Not answering your question but as a workaround you could loop through the list of appenders returned and find the first (or named) instance of AdoNetAppender you're looking for.
Regards,
Dag
|
|
|
|
|
Gourlay, Colin
 |
| 10/20/2008 10:29 AM |
|
Hi Dag.
Thanks for your comments.
The appenders collection returned only ever has one item in it - a TextWriterAppender. It is as if the config file is not being found and a default appender is being used.
Any other thoughts?
Config file follows:
<log4net> <root> <level value="INFO"/> <appender-ref ref="LogToSqlServer"/> </root>
<appender name="LogToSqlServer" type="log4net.Appender.AdoNetAppender">
... lots of stuff in here ...
</appender> </log4net>
|
|
|
|
|
|
| You are not authorized to post a reply. |
|
|
|
ActiveForums 3.7
|