开发者

Retrieving parameter values using Microsoft Enterprise Library Exception Handler

We are using Enterprise Library for all our logging and exception handling needs in our app. We have added an email listener to send all the caught exceptions in email to the administrator. One requirement is that when an exception occurs in a method we need to retrieve the parameter values of the method if any and attach it 开发者_JS百科to the exception details in the email sent. Is it possible without writing a custom logger?


Just create a custom exception, setting the message to the parameters:

try {
  ...
} catch(Exception ex) {
  var customException = new CustomException(ex, string.format("Param1 {0}, Param2 {1}", param1, param2));
  bool rethrow = ExceptionPolicy.HandleException(customException, PolicyName);
}

verified that in fact the ExceptionFormatter class will indeed traverse all inner exceptions, so your CustomException could be as simple as

public class CustomException : Exception
{
    public CustomException(string message, Exception innerException) : base(message, innerException)
    {
    }
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜