【问题标题】:Enterprise library 5.0 in a c# class library projectC#类库项目中的企业库5.0
【发布时间】:2011-03-30 23:22:36
【问题描述】:

我在 VS 2010 中有一个 c# 类库项目,它输出一个 dll。我在我的解决方案中添加了一个可执行项目,我需要从该项目开始调试我的 dll。我没有具有 app.config 的主机应用程序。我可以在我的类库项目中使用 Enterprise Libray(尤其是异常处理)吗?如果是,由于没有 app.config,我该如何定义异常处理策略?

谢谢!

【问题讨论】:

    标签: .net project enterprise-library class-library


    【解决方案1】:

    您可以将Fluent Configuration API 与企业库 5 一起使用

    关于Exception Handling。 (来自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);
    

    【讨论】:

      猜你喜欢
      • 2012-09-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多