Friday, May 18, 2012
 
The best way to analyze your logs! Minimize
 Log4Net Mail archive   

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.

Subject: AdoNetAppender Connection String
Prev Next
You are not authorized to post a reply.

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.
Forums > Log4Net > Log4Net Mail archive > AdoNetAppender Connection String



ActiveForums 3.7

 

 

 

 

 

 

 

 

Log4Net Dashboard

Log analysis and monitoring made easy!

Log4Net Dashboard is a log viewer that can read log statements from a variety of logging output targets.

You can download a free developer version.

  

Check it out!

On the demonstration site you can try it  with live data.demo.l4ndash.com - Try Log4Net Dashboard with live data

The mail archive is a copy of all the mail sent to the mail address: log4net-user@logging.apache.org, organized as a forum.

If you would like to participate in the mail list, send a mail to log4net-user-subscribe@logging.apache.org.

More information about the mailing list is available on: http://logging.apache.org/log4net/support.html

 

A complete topic list is available and can be viewed here (warning, it takes some time to load)

 

Copyright 2005-2008 by FaktNet AS Terms Of Use Privacy Statement