这个问题的任何想法 [英] Any idea of this issue
问题描述
嗨
我有一个应用程序,其中包含许多try
和catch
块,这对于错误处理非常有用.
I have an application that holds a lot of try
and catch
blocks which is good for error handling.
现在我需要在向数据库报告错误的catch
块中添加一个函数,我只需要将该函数放入catch
块
Now i need to add a function into the catch
block that reports error to the database, i only need to put the function into the catch
block
如果您的应用程序与我的应用程序不同,那就很好.
that is fine if you have a small application unlike mine.
推荐答案
这是
This is a repost of this question. Please do not repost; just edit your original question.
对于普通异常,请创建一个常规函数,该函数会将所有异常记录到数据库中,例如
For normal exception create a general function which logs any exception into the database like
public void LogException(Exception ex)
{
//Store ex.Message / ex.StackTrace and whatever else into database
}
现在从catch块调用此函数进行记录.
Now from catch block call this function to log.
catch(Exception ex)
LogException(ex);
您还可以检查
You can also check the Type of exception inside LogException
function to log specific values for an exception.
PostSharp可能是一个不错的选择,使用属性记录异常
It''s likely that the PostSharp is a good choice,use attribute to log exceptions
这篇关于这个问题的任何想法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!