Can you pull the connectionString for a log4net AdoNetAppender from elsewhere in a web.config file?

前端 未结 5 1872
花落未央
花落未央 2020-12-05 03:53

I already have a db connection string in my web.config file. I scanned the log4net docs, but can\'t seem to find a way to use it within the log4net section of my web.config

5条回答
  •  一整个雨季
    2020-12-05 04:27

    Create a class that extends AdoNetAppender - say, WebAppAdoNetAppender. Implement the ConnectionString property in that class, and retrieve the connection string from your web.config file in that property setter.

    
        
        ...
    

    ...

    public class WebAppAdoNetAppender : log4net.Appender.AdoNetAppender
    {
        public new string ConnectionString
        {
            get { return base.ConnectionString; }
            set { base.ConnectionString = ...   }
        }
    }
    

提交回复
热议问题