1

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 app.config?

Thanks!

1 Answer 1

1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.