You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-user@logging.apache.org by "Gourlay, Colin" <cg...@ebs.hw.ac.uk> on 2008/10/16 15:28:16 UTC

AdoNetAppender Connection String

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[0] as AdoNetAppender;

                // return connection string if it is found
                return appender.ConnectionString ?? string.Empty;
            }
        }

________________________________

Edinburgh Business School is a Charity Registered in Scotland, SC026900

RE: AdoNetAppender Connection String

Posted by "Gourlay, Colin" <cg...@ebs.hw.ac.uk>.
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>




-----Original Message-----
From: Dag Christensen [mailto:Dag.Christensen@vismaretail.no]
Sent: 16 October 2008 14:58
To: Log4NET User
Subject: RE: AdoNetAppender Connection String
Importance: Low

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


From: Gourlay, Colin [mailto:cg1@ebs.hw.ac.uk]
Sent: Thursday, October 16, 2008 3:28 PM
To: log4net-user@logging.apache.org
Subject: AdoNetAppender Connection String

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[0] as AdoNetAppender;

                // return connection string if it is found
                return appender.ConnectionString ?? string.Empty;
            }
        }

________________________________________

Edinburgh Business School is a Charity Registered in Scotland, SC026900
###########################################

This message has been scanned by F-Secure Anti-Virus for Microsoft Exchange.
For more information, connect to http://www.f-secure.com/



RE: AdoNetAppender Connection String

Posted by Dag Christensen <Da...@vismaretail.no>.
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


From: Gourlay, Colin [mailto:cg1@ebs.hw.ac.uk] 
Sent: Thursday, October 16, 2008 3:28 PM
To: log4net-user@logging.apache.org
Subject: AdoNetAppender Connection String

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[0] as AdoNetAppender;

                // return connection string if it is found
                return appender.ConnectionString ?? string.Empty;
            }
        }

________________________________________

Edinburgh Business School is a Charity Registered in Scotland, SC026900
###########################################

This message has been scanned by F-Secure Anti-Virus for Microsoft Exchange.
For more information, connect to http://www.f-secure.com/