【问题标题】:How to add information in ASP.NET Exception Stack如何在 ASP.NET 异常堆栈中添加信息
【发布时间】:2012-04-13 02:48:45
【问题描述】:

我想添加一些关于程序如何工作的额外信息,如果有异常,那么我喜欢将这些额外信息写在异常报告中,即 ELMAH 记录的正常全部信息。

如果没有例外,那么我不需要这些信息,就让它过去吧。所以我不认为将所有内容都写在日志中对我来说是个好主意。

请告知我如何编写将记录异常的额外信息。谢谢

【问题讨论】:

    标签: c# asp.net exception elmah


    【解决方案1】:

    您可以创建自己的异常类

    public class YourCustomException : Exception
    {
        public YourCustomException(Exception inner, string message)
        : base(inner, message)
        {
        }
    
    }
    

    ...并向消息中添加其他信息。

    try
    {
       // ...
    }
    catch(Exception ex)
    {
        throw new YourCustomException(ex, "More information");
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-18
      • 2011-08-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多