我試圖將所有的配置和在一個基本文件夾(C:\ MY_PRODUCT \)登錄我的應用程序的文件具有以下結構:使用外部與環境變量log4net的配置文件
C:\MY_PRODUCT\CONFIGURATION\
C:\MY_PRODUCT\LOGS\
...
我使用log4net的進行記錄,並使用log4net的FileAppender配置環境變量正常工作:
<appender name="FileAppender" type="log4net.Appender.RollingFileAppender">
<file value="${PRODUCT_BASE}\LOGS\file.log" />
<threshold value="ALL" />
<appendToFile value="true" />
<maximumFileSize value="10MB" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="200" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="[%date{O}] [%-5level] [%-3thread] [%logger] [%method] %message%newline" />
</layout>
然而,通過在新文件中分離log4net的配置(C:\ MY_PRODUCT \配置\ Log4Net.config):
,使用環境變量通過設置屬性 ConfigSource當log4net的是無法找到這個配置文件<log4net configSource="${PRODUCT_BASE}\CONFIGURATION\Log4Net.config" />
請注意,如果我通過其值(路徑C:\ MY_PRODUCT)替換$ {PRODUCT_BASE}環境變量,它將正常工作,並且log4net能夠找到配置文件。
log4net的日誌:
我啓用了log4net的調試模式,看看會發生什麼,我得到了以下錯誤:
log4net的:錯誤無法解析配置文件。指定爲: System.Configuration.ConfigurationErrorsException:無法打開configSource文件'$ {PRODUCT_BASE} \ config \ Log4Net.config'。 (Tests \ bin \ Debug \ MY_PRODUCT.Core.Tests.dll.config line 10) at System.Configuration.BaseConfigurationRecord.EvaluateOne(String [] keys,SectionInput input,Boolean isTrusted,FactoryRecord factoryRecord,SectionRecord sectionRecord,Object parentResult) 在System.Configuration.BaseConfigurationRecord.Evaluate(factoryRecord factoryRecord,sectionRecord sectionRecord,對象parentResult,布爾getLkg,布爾getRuntimeObject,對象&結果,對象& resultRuntimeObject)在System.Configuration.BaseConfigurationRecord.GetSectionRecursive(字符串configKey,布爾getLkg,布爾的checkPermission ,Boolean getRuntimeObject,Boolean requestIsHere,Object & result,Object & resultRuntimeObject) at System.Configuration.BaseConfigurationRecord。 GetSectionRecursive(字符串configKey,布爾getLkg,布爾的checkPermission,布爾getRuntimeObject,布爾requestIsHere,對象&結果,對象& resultRuntimeObject)在System.Configuration.BaseConfigurationRecord.GetSectionRecursive(字符串configKey,布爾getLkg,布爾的checkPermission,布爾getRuntimeObject,布爾requestIsHere ,對象&結果,在System.Configuration.ConfigurationManager在System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(字符串sectionName) 對象& resultRuntimeObject) 在System.Configuration.BaseConfigurationRecord.GetSection(字符串configKey) 。 GetSection(String sectionName) at log4net.Config.XmlConfigurato r.InternalConfigure(ILoggerRepository庫)
如果log4net的是擴展性能ConfigSource的環境變量,我不知道,我已經張貼在Apache log4net的問題平臺的問題,直到他們回答或解決問題,是有任何方式來實現這種方法?