2011-10-19 4 views
0

로깅을 위해 엔터프라이즈 라이브러리를 사용하고 있습니다. 따라서 구성을 유지하려면 클라이언트의 app.config를 사용하고 있습니다. 요구 사항이 "EL 구성 및 UI 구성 분할"로 변경되었습니다. 나는 enterpriseLibrary.ConfigurationSource를 사용하여 그것을 수행했다. 구성을 app.config (UI의 경우) 및 EL.config (EL의 경우)로 분할하십시오.App.config 및 엔터프라이즈 라이브러리

이제이 EL> config의 단순한 존재가 사용자에게 보이지 않도록 app.cpnfig에서이 EL.config에 대한 참조를 숨기려고합니다.

의 App.config 코드 :

<enterpriseLibrary.ConfigurationSource selectedSource="EntLib Configuration Source"> 
<sources> 
    <add name="EntLib Configuration Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
    filePath="C:\My.CommonServices.Logging\My.CommonServices.Logging\EL.config" /> 
</sources> 

답변

5

프로그래밍 방식으로 외부 구성 파일을로드 FileConfigurationSource를 사용할 수 있습니다. 당신이 좋아하는 기능에 액세스 할 수 있습니다 수행되는 일단

FileConfigurationSource fcs = 
    new FileConfigurationSource(
     @"C:\My.CommonServices.Logging\My.CommonServices.Logging\EL.config" 
    ); 

var builder = new ConfigurationSourceBuilder(); 
builder.UpdateConfigurationWithReplace(fcs); 

EnterpriseLibraryContainer.Current = 
    EnterpriseLibraryContainer.CreateDefaultContainer(fcs); 

: 응용 프로그램로드 또는 초기화하는 동안

당신은 당신의 외부 구성 파일을로드 할 수있는 유일한 "트릭은"보장됩니다

LogWriter logWriter = EnterpriseLibraryContainer.Current.GetInstance<LogWriter>(); 
logWriter.Write("Test"); 

구성 파일은 예상 한 위치에 항상 존재합니다 (절대 또는 상대).

+0

감사합니다. – Deimos

관련 문제