开发者

Enterprise library 5.0 in a c# class library project

I have a c# class library project in VS 2010 which outputs a dll. I added a executable project in my solution that I need to start with so I can debug my dll. I don't have a host application which has the app.config. Can I use Enterprise Libray (especially exception handling) in my class library project? If yes, how can I define the Exception Handling Policies since there is no 开发者_JS百科app.config?

Thanks!


You can use the Fluent Configuration API with enterprise library 5

With respects to Exception Handling. (from msdn)

var builder = new ConfigurationSourceBuilder();

builder.ConfigureExceptionHandling()
       .GivenPolicyWithName("MyPolicy")
       .ForExceptionType<NullReferenceException>()
         .LogToCategory("General")
           .WithSeverity(System.Diagnostics.TraceEventType.Warning)
           .UsingEventId(9000)
         .WrapWith<InvalidOperationException>()
           .UsingMessage("MyMessage")
         .ThenNotifyRethrow();

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜