0

엔터프라이즈 라이브러리 예외 처리 응용 프로그램 블록 사용에 대한 질문이 있습니다.엔터프라이즈 라이브러리 예외 처리 "프로세스"메서드

첫 번째는 "ExceptionManager.Process"메소드입니다. 내가 문서에서 이해 한 것은 당신이 원하는 메소드를 실행할 수 있다는 것과 ExceptionManager가 ExceptionManager를 처리하고 ExceptionManager가 try-catch 블록을 필요로하지 않는다는 것입니다. 하지만 그것을 사용할 때 예외가 throw됩니다.

builder.ConfigureExceptionHandling() 
       .GivenPolicyWithName("Data Access Policy") 
       .ForExceptionType<Exception>() 
       .LogToCategory("General") 
       .WithSeverity(System.Diagnostics.TraceEventType.Error) 
       .UsingEventId(9000) 
       .WrapWith<InvalidOperationException>() 
       .UsingMessage("MyMessage").ThenDoNothing(); 
     #endregion 

     var configSource = new DictionaryConfigurationSource(); 
     builder.UpdateConfigurationWithReplace(configSource); 
     EnterpriseLibraryContainer.Current = EnterpriseLibraryContainer.CreateDefaultContainer(configSource); 

     #endregion 

     var exManager = EnterpriseLibraryContainer.Current.GetInstance<ExceptionManager>(); 
     exManager.Process(GenerateException, "Data Access Policy"); 
    } 

    private static void GenerateException() 
    { 
     throw new NullReferenceException(); 
    } 

응용 프로그램 블록 구성에 Fluent-API를 사용했습니다. 데이터베이스에 예외를 기록하고 잘 구성했습니다. ExeptionManager.HandleException은 잘 작동하지만 try-catch 블록에 있어야합니다.

중단없이 try-catch 블록없이 예외를 처리하는 "프로세스"방법은 어떻게 사용할 수 있습니까?

답변

2

로깅 블록을 구성해야합니다. 받은 예외를 게시하지 않았지만 InnerException 속성을 확인하면 메시지를 찾을 수 있습니다.

유형 LogWriter에는 액세스 가능한 생성자가 없습니다.

예외 처리 블록을 사용하여 데이터베이스에 로그온하려면 예외 처리 블록, 로깅 블록 및 데이터 액세스 블록을 구성해야합니다. 귀하의 경우는 다음과 같이 보일 것입니다 : 또한

var builder = new ConfigurationSourceBuilder(); 

builder.ConfigureExceptionHandling() 
    .GivenPolicyWithName("Data Access Policy") 
    .ForExceptionType<Exception>() 
    .LogToCategory("General") 
    .WithSeverity(System.Diagnostics.TraceEventType.Error) 
    .UsingEventId(9000) 
    .WrapWith<InvalidOperationException>() 
    .UsingMessage("MyMessage").ThenDoNothing(); 

builder.ConfigureLogging() 
    .WithOptions 
     .DoNotRevertImpersonation() 
    .LogToCategoryNamed("General") 
     .WithOptions.SetAsDefaultCategory() 
     .SendTo.Database("Database Trace Listener") 
     .UseDatabase("Logging") 
     .WithAddCategoryStoredProcedure("AddCategory") 
     .WithWriteLogStoredProcedure("WriteLog"); 

builder.ConfigureData() 
    .ForDatabaseNamed("Logging") 
    .ThatIs.ASqlDatabase() 
    .WithConnectionString(@"Data Source=.\SQLEXPRESS;DataBase=LoggingDefault;Integrated Security=True;") 
    .AsDefault(); 

var configSource = new DictionaryConfigurationSource(); 
builder.UpdateConfigurationWithReplace(configSource); 
EnterpriseLibraryContainer.Current = EnterpriseLibraryContainer.CreateDefaultContainer(configSource); 


var exManager = EnterpriseLibraryContainer.Current.GetInstance<ExceptionManager>(); 
exManager.Process(GenerateException, "Data Access Policy"); 

, 당신은 예외를 삼키는 및 던지는 또는 rethrowing되지 않기 때문에 당신이 구성에서 Wrap<> 필요하지 않습니다 메모를.