如何使用异常管理企业库6.0 [英] How To Use Exception Manager Enterprise Library 6.0

查看:466
本文介绍了如何使用异常管理企业库6.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用企业库6.0,在下面的代码中出现此错误:

When using Enterprise Library 6.0, this error occurs in the code below:

bool rethrow = ExceptionPolicy.HandleException(ex, "ReplacePolicy1")

必须在使用SetExceptionManager方法ExceptionPolicy类设置ExceptionManager。

"Must set an ExceptionManager in the ExceptionPolicy class using the SetExceptionManager method."

在企业库5.0这个代码工作:

In Enterprise Library 5.0 this code worked:

public static bool HandleException(Exception exception, string PolicyName)
{
    ExceptionManager exManager = EnterpriseLibraryContainer.Current.GetInstance<ExceptionManager>();
    ExceptionPolicy.SetExceptionManager(exManager);
    bool rethrow = ExceptionPolicy.HandleException(ex, "ReplacePolicy1");
    return reThrow;
}



但在企业图书馆6.0 EnterpriseLibraryContainer类没有找到。
我想获得ExceptionManager的实例。
我该如何解决这个问题?

But in Enterprise Library 6.0 the EnterpriseLibraryContainer class is not found. I want get instance of ExceptionManager. How do I solve this problem ?

推荐答案

EnterpriseLibraryContainer是为企业库6的发行版中删除有一个

EnterpriseLibraryContainer was removed for the release of Enterprise Library 6. There is a new approach for bootstrapping the application blocks in Enterprise Library 6. If you want to get an instance of ExceptionManager you can use the factory:

IConfigurationSource config = ConfigurationSourceFactory.Create();
ExceptionPolicyFactory factory = new ExceptionPolicyFactory(config);

ExceptionManager exManager = factory.CreateManager();

要配置块从上面使用静态外墙可以使用SetExceptionManager方法,并提供ExceptionManager

To configure the blocks to use the static facades you can use the SetExceptionManager method and supply the ExceptionManager from above:

ExceptionPolicy.SetExceptionManager(factory.CreateManager());

本只需要在应用程序启动一次。

This only needs to be done once at application startup.

这篇关于如何使用异常管理企业库6.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆