通过Try ... Catch收集错误 [英] Error Collection Via Try ...Catch

查看:49
本文介绍了通过Try ... Catch收集错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我想捕获应用程序中发生的所有错误.


我在所有事件和功能中都使用了try catch.在捕获中,我已抛出异常消息.

现在我想在文件或表上存储以下信息(日期时间,错误消息,表单名称)

有没有办法在一个地方捕获所有异常,或者我需要为所有catch块编写代码..



我该怎么办?


问候,
Pal

Hi All,

I want to catch the all errors occurred in the application.


I have used Try catch in all events and functions. in the catch I have Throw the exception message.

Now I want to store on a File or a table with the information( Date time,error message,Form name)

is there any way to capture all exception in a single place or I need to write code for all the catch blocks..



how can I do this?


Regards,
Pal

推荐答案

可能是从
Might be good place to start with AnLogger - ASP.NET Logger[^]

Hope it helps


创建Logger方法并将异常数据传递到Logger.

这样的事情应该做

Create a Logger method and pass the exception data to the Logger.

Something like this should do

public static class Logger
    {
         string logFilePath ;
        private SetLogFilePath();
        public LogMessage(string Message);

    }



在所有catch块中调用log方法.如果您发现可以捕获所有应用错误的东西,那么该线程将为您提供帮助.

http://stackoverflow.com/Questions/337702/c-sharp-how-to-implement-one-catchem-all-exception-handler-with-resume [



Call the log method in all catch blocks.if you looking for something that catches all the applcation errors then this thread will help you.

http://stackoverflow.com/questions/337702/c-sharp-how-to-implement-one-catchem-all-exception-handler-with-resume[Catch all errors in the application]

But my suggestion would be to use individual exception handlers rather than doing all once.As in windows if application level exception is caught and handled application continues to run but will not respond to any of the user actions like button click events and other events will not work until the application is restarted.


这篇关于通过Try ... Catch收集错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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