logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gourlay, Colin" <...@ebs.hw.ac.uk>
Subject AdoNetAppender Connection String
Date Thu, 16 Oct 2008 13:28:16 GMT
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

Mime
View raw message