需要我的错误记录机制的评论评论

时间:2021-09-16 21:47:14

On every break on the Production/QA/Dev getting to the root of the exception is very crucial and time taking process.

在生产/质量保证/开发的每个休息时间到达异常的根源是非常关键和时间的过程。

As the web applications are in multi user environment and Stateless \ Asynchronous (HTTP) ,its really a tough job to look at the Eventviewer / log files and root cause an issue reported by the end user; Also it depends on how educated the End-user to explain the issue in detail.

由于Web应用程序处于多用户环境和无状态\异步(HTTP)中,因此查看Eventviewer /日志文件和root导致最终用户报告的问题确实非常困难;此外,它取决于最终用户如何教育细节解释问题。

I came up with a creative way to log the Exceptions. Which makes the job easier for the End user and Dev team?

我想出了一种记录异常的创造性方法。这使得最终用户和开发团队的工作更轻松?

We will follow a signature to log the Exceptions into an XML file, and which can be processed remotely for viewing or reports on Exceptions

我们将遵循签名将异常记录到XML文件中,并且可以远程处理以查看或报告异常

The signature of the Static method in the Error logging class is as follows

Error日志记录类中的Static方法的签名如下所示

WriteLog (Unique Number , Module Name, Priority, Layer ,String Custom Message,Exception with Stack Trace);

WriteLog(唯一编号,模块名称,优先级,层,字符串自定义消息,带堆栈跟踪的异常);

I know there are many reusable Exception handling libraries, but what I was looking at is a unique number to track the issue that should get displayed to the end user

我知道有许多可重用的异常处理库,但我所看到的是一个唯一的数字来跟踪应该显示给最终用户的问题

Response back to the User :

回复用户的回复:

If the Exception is expected to handled and consumed then it’s up the developer to show the valid user-friendly message to the end user. Incase of any unexpected or exception is thrown to the Application layer ( Global .asax ) the Response would be cleared and Custom Message in HTML will be written back to the user with the Unique ID like the below one

如果预计会处理和消耗Exception,那么开发人员就会向最终用户显示有效的用户友好消息。将任何意外或异常引发到应用程序层(全局.asax),将清除响应,并将HTML中的自定义消息写回具有唯一ID的用户,如下所示

“ An Unexpected Error has occurred , the Exception has be recorded for further action; Please use the # Unique number generated to communicate the Support team “

“发生了意外错误,已记录异常以便采取进一步行动;请使用生成的#Unique号码与支持团队进行沟通“

Parameter Details :

参数详情:

Unique Number : This is the unique number generated for every Exception, a read only (get) property in the ErrorLogging Class which would be unique per exception , this would be concatenation of the Hour+Minutes+Seconds+Milliseconds; initially I thought to use GUID but then it would be tough for the end user to remember the GUID to report the issue.

唯一编号:这是为每个Exception生成的唯一编号,ErrorLogging类中的只读(get)属性,每个异常都是唯一的,这可以是Hour + Minutes + Seconds + Milliseconds的连接;最初我想使用GUID,但最终用户很难记住报告问题的GUID。

Public string strExceptionID {

公共字符串strExceptionID {

      Get { 

      return  DateTime.Now.ToString(“HHmmssfff”);

          }    

     }

Module Name : This would be a Static Enum variable with Module Name Ex : enum ModuleName {

模块名称:这将是一个静态枚举变量,其模块名称为Ex:enum ModuleName {

    Module1, 

    Module2, 

    Module3  };

Priority: This would be a Static Enum variable with Priority , developer has to decide the priority like if it’s a validation fail of Date or integer format use “Low” or if its unexpected in a Business layer call then use “2” .

优先级:这将是具有优先级的静态枚举变量,开发人员必须确定优先级,如果它是日期或整数格式的验证失败使用“低”或者如果它在业务层调用中意外,则使用“2”。

I think Priority High should be used in only in DAL or in Business Logic Layer or like if the interface to SAP or Ariba fails. Ex : enum Priority {

我认为Priority High只应在DAL或业务逻辑层中使用,或者如果SAP或Ariba的接口失败则应该使用。例如:枚举优先级{

        High =1, 
      Medium =2, 
      Low =3, };

Layer :

This would be a Static Enum variable with Layer Ex : enum Layer {

这将是一个Static Enum变量,其中包含Layer Ex:enum Layer {

      Presentation, 
      Business, 
      DataAccess 
            };

String Custom Message :

String自定义消息:

This is optional parameter, and its upto the developer to supply an information to help explain the Reason or Empty string can be passed.

这是可选参数,它由开发人员提供信息以帮助解释Reason或Empty字符串可以传递。

Exception with Stack Trace : This would the Exception object which would be further processed inside the method.

堆栈跟踪的异常:这将是Exception对象,它将在方法内进一步处理。

The processing done inside the error log method :

在错误日志方法内完成的处理:

The method will additionally get the logged-in Userid and timestamp and write it to the XML File.

该方法还将获取登录的Userid和时间戳,并将其写入XML文件。

Pros :

-> XML Logging will enable us to process an use it in any manner -> The exceptions can be viewed remotely in a browser. -> Easy to trace and find any exception. -> We can search , sort exception based on Module, Priority , Time Stamp , UserID…etc -> We can generate reports @ Module level , Layer wise , Priority , Time…

- > XML Logging将使我们能够以任何方式处理它 - >可以在浏览器中远程查看异常。 - >易于追踪并发现任何异常。 - >我们可以搜索,根据模块,优先级,时间戳,用户ID等排序异常 - >我们可以生成报告@模块级别,层次,优先级,时间......

Cons : Dependency on the XML file, if its lost all the exceptions would go for a toss, we can overcome this in two ways; writing the xml to DB on timely basis OR write this on top of Event viewer logging as we'll always have the backup.

缺点:对XML文件的依赖,如果丢失所有异常将会折腾,我们可以通过两种方式克服这个问题;及时将xml写入DB或将其写在事件查看器日志记录之上,因为我们将始终拥有备份。

Based on the review comments I'll post the XML Schema and the ASPX page to view and search the errors.

根据评论评论,我将发布XML Schema和ASPX页面来查看和搜索错误。

Please take time to review and give ur feedback.

请花点时间查看并提供反馈。

6 个解决方案

#1


I have a bit of a bug bear with people rewriting tracing APIs without really understanding what the platform will give them out of the box. So lets look at you API call:

我有一个小问题,人们重写跟踪API而没有真正理解平台将开箱即用的东西。那么让我们来看看你的API调用:

WriteLog (Unique Number , Module Name, Priority, Layer ,String Custom Message,Exception with Stack Trace);

WriteLog(唯一编号,模块名称,优先级,层,字符串自定义消息,带堆栈跟踪的异常);

Unique Number: Implement a TraceListener (check out System.Diagnostics) which adds this unique number, don't make the calling code generate it.

唯一编号:实现一个TraceListener(检查System.Diagnostics),它添加了这个唯一的编号,不要让调用代码生成它。

Module Name: The stack trace will provide this kind of detail - assuming you know what code is in what module. In fact it probably doesn't matter from a fault finding perspective.

模块名称:堆栈跟踪将提供此类详细信息 - 假设您知道哪个模块中的代码。事实上,从故障发现的角度来看,这可能并不重要。

Priority: The System.Diagnostics API provides the following level of severity. Information, Warning and Error (as well as Debug). Now priority is in the eye of the beholder, from a development point of view - it is either "hey this happened, you might like to know (information)", he "this looks a bit suss be we can continue anyway (warning)" and "oh heck, I'm broken (error)".

优先级:System.Diagnostics API提供以下级别的严重性。信息,警告和错误(以及调试)。从发展的角度来看,现在优先考虑的是旁观者的眼睛 - 它是“嘿,这发生了,你可能想知道(信息)”,“他看起来有点糟糕,我们可以继续(警告) “而且,哎呀,我坏了(错误)”。

Layer: What is the real difference between module and error here? Once again, if you use System.Diagnostics correctly environmental information such as what computer this happened on can be added dynamically. You wouldn't want to rely on developers to do this consistently.

层:模块和错误之间的真正区别在于什么?再一次,如果您正确使用System.Diagnostics,可以动态添加环境信息,例如发生了什么计算机。您不希望依赖开发人员始终如一地执行此操作。

Custom Message: Yep - this is reasonable. For bonus points make it take a format string (actually - Trace.TraceError/TraceWarning/TraceInformation already do this. So just use that.

自定义消息:是的 - 这是合理的。对于奖励积分,它需要一个格式字符串(实际上 - Trace.TraceError / TraceWarning / TraceInformation已经这样做了。所以只需使用它。

Exception: If you use Trace.TraceError (et.al) then you can use the format string. Not every error has an exception so you don't necessarily need to produce an API that accepts them, as long as they take a format string - you can do this:

例外:如果使用Trace.TraceError(et.al),则可以使用格式字符串。并非每个错误都有异常,因此您不一定需要生成接受它们的API,只要它们采用格式字符串 - 您可以这样做:

Trace.TraceError( "The user provided the following input '{0}'. The follow exception was:\r\n{1}", userInput, ex );

Trace.TraceError(“用户提供了以下输入'{0}'。以下例外是:\ r \ n {1}”,userInput,ex);

Anyway - I guess what I am saying is that if you are writing this in .NET like it looks like you are - spend half a day surfing the System.Diagnostics documentation. You might negate the need to write your API.

无论如何 - 我想我所说的是,如果你在.NET中写这个就像你看起来那样 - 花半天时间浏览System.Diagnostics文档。您可能无需编写API。

#2


I have two remarks:

我有两个评论:

  1. I don't like relying on timestamps as unique identifiers. If you know for sure your site is not going to be loaded it's ok, but under heavy stress the milliseconds resolution may not be enough. The reason being the milliseconds counter might have a granularity larger than one. This means two very close calls might get the same timestamp. Not very likely, but why limit yourself?

    我不喜欢依赖时间戳作为唯一标识符。如果你确定你的网站不会被加载它没关系,但是在压力很大的情况下,毫秒的分辨率可能还不够。原因是毫秒计数器的粒度可能大于1。这意味着两个非常接近的调用可能会获得相同的时间戳。不太可能,但为什么限制自己?

  2. Presenting a code to the user along with a human readable message is nice, but you should never expect the user to contact you and point you to the error. If you're looking for feedback on errors, just have the logger send you an email whenever the error occurs (which means you will be able to use a real unique identifier, like a GUID, rather than a timestamp).

    向用户呈现代码以及人类可读的消息很不错,但您绝不应该期望用户与您联系并指出错误。如果您正在寻找有关错误的反馈,只需让记录器在发生错误时向您发送电子邮件(这意味着您将能够使用真正的唯一标识符,如GUID,而不是时间戳)。

#3


For the ExceptionID, you might actually be best-off with a GUID. The date format will not be unique, because it rolls over every day, and also, you may get multiple errors in the same millisecond.

对于ExceptionID,您实际上可能最好使用GUID。日期格式不是唯一的,因为它每天都会翻转,而且,您可能会在同一毫秒内收到多个错误。

#4


Emphasizing the point made by previous reviewers: You're likely to get multiple exceptions in the same millisecond, if and when there are failures caused by race conditions.

强调先前评论者提出的观点:如果竞争条件导致失败,您可能会在相同的毫秒内获得多个例外。

#5


If this is an ASP.NET application, then you should look into ASP.NET Health Monitoring. Even by default, it will emit detailed traces into the event log. You can configure it to produce the same output in XML files, and add your own tracing as well.

如果这是一个ASP.NET应用程序,那么您应该查看ASP.NET运行状况监视。即使默认情况下,它也会在事件日志中发出详细的跟踪信息。您可以将其配置为在XML文件中生成相同的输出,并添加自己的跟踪。

#6


Send out an email including the error message and error number is a more efficient way, can't expect end user to report every fail they found. But emails will get all the fails. It's easy for SAP or Ariba to send out an email at some point.

发送包含错误消息和错误号的电子邮件是一种更有效的方式,不能指望最终用户报告他们发现的每个失败。但电子邮件将全部失败。 SAP或Ariba很容易在某个时候发送电子邮件。

#1


I have a bit of a bug bear with people rewriting tracing APIs without really understanding what the platform will give them out of the box. So lets look at you API call:

我有一个小问题,人们重写跟踪API而没有真正理解平台将开箱即用的东西。那么让我们来看看你的API调用:

WriteLog (Unique Number , Module Name, Priority, Layer ,String Custom Message,Exception with Stack Trace);

WriteLog(唯一编号,模块名称,优先级,层,字符串自定义消息,带堆栈跟踪的异常);

Unique Number: Implement a TraceListener (check out System.Diagnostics) which adds this unique number, don't make the calling code generate it.

唯一编号:实现一个TraceListener(检查System.Diagnostics),它添加了这个唯一的编号,不要让调用代码生成它。

Module Name: The stack trace will provide this kind of detail - assuming you know what code is in what module. In fact it probably doesn't matter from a fault finding perspective.

模块名称:堆栈跟踪将提供此类详细信息 - 假设您知道哪个模块中的代码。事实上,从故障发现的角度来看,这可能并不重要。

Priority: The System.Diagnostics API provides the following level of severity. Information, Warning and Error (as well as Debug). Now priority is in the eye of the beholder, from a development point of view - it is either "hey this happened, you might like to know (information)", he "this looks a bit suss be we can continue anyway (warning)" and "oh heck, I'm broken (error)".

优先级:System.Diagnostics API提供以下级别的严重性。信息,警告和错误(以及调试)。从发展的角度来看,现在优先考虑的是旁观者的眼睛 - 它是“嘿,这发生了,你可能想知道(信息)”,“他看起来有点糟糕,我们可以继续(警告) “而且,哎呀,我坏了(错误)”。

Layer: What is the real difference between module and error here? Once again, if you use System.Diagnostics correctly environmental information such as what computer this happened on can be added dynamically. You wouldn't want to rely on developers to do this consistently.

层:模块和错误之间的真正区别在于什么?再一次,如果您正确使用System.Diagnostics,可以动态添加环境信息,例如发生了什么计算机。您不希望依赖开发人员始终如一地执行此操作。

Custom Message: Yep - this is reasonable. For bonus points make it take a format string (actually - Trace.TraceError/TraceWarning/TraceInformation already do this. So just use that.

自定义消息:是的 - 这是合理的。对于奖励积分,它需要一个格式字符串(实际上 - Trace.TraceError / TraceWarning / TraceInformation已经这样做了。所以只需使用它。

Exception: If you use Trace.TraceError (et.al) then you can use the format string. Not every error has an exception so you don't necessarily need to produce an API that accepts them, as long as they take a format string - you can do this:

例外:如果使用Trace.TraceError(et.al),则可以使用格式字符串。并非每个错误都有异常,因此您不一定需要生成接受它们的API,只要它们采用格式字符串 - 您可以这样做:

Trace.TraceError( "The user provided the following input '{0}'. The follow exception was:\r\n{1}", userInput, ex );

Trace.TraceError(“用户提供了以下输入'{0}'。以下例外是:\ r \ n {1}”,userInput,ex);

Anyway - I guess what I am saying is that if you are writing this in .NET like it looks like you are - spend half a day surfing the System.Diagnostics documentation. You might negate the need to write your API.

无论如何 - 我想我所说的是,如果你在.NET中写这个就像你看起来那样 - 花半天时间浏览System.Diagnostics文档。您可能无需编写API。

#2


I have two remarks:

我有两个评论:

  1. I don't like relying on timestamps as unique identifiers. If you know for sure your site is not going to be loaded it's ok, but under heavy stress the milliseconds resolution may not be enough. The reason being the milliseconds counter might have a granularity larger than one. This means two very close calls might get the same timestamp. Not very likely, but why limit yourself?

    我不喜欢依赖时间戳作为唯一标识符。如果你确定你的网站不会被加载它没关系,但是在压力很大的情况下,毫秒的分辨率可能还不够。原因是毫秒计数器的粒度可能大于1。这意味着两个非常接近的调用可能会获得相同的时间戳。不太可能,但为什么限制自己?

  2. Presenting a code to the user along with a human readable message is nice, but you should never expect the user to contact you and point you to the error. If you're looking for feedback on errors, just have the logger send you an email whenever the error occurs (which means you will be able to use a real unique identifier, like a GUID, rather than a timestamp).

    向用户呈现代码以及人类可读的消息很不错,但您绝不应该期望用户与您联系并指出错误。如果您正在寻找有关错误的反馈,只需让记录器在发生错误时向您发送电子邮件(这意味着您将能够使用真正的唯一标识符,如GUID,而不是时间戳)。

#3


For the ExceptionID, you might actually be best-off with a GUID. The date format will not be unique, because it rolls over every day, and also, you may get multiple errors in the same millisecond.

对于ExceptionID,您实际上可能最好使用GUID。日期格式不是唯一的,因为它每天都会翻转,而且,您可能会在同一毫秒内收到多个错误。

#4


Emphasizing the point made by previous reviewers: You're likely to get multiple exceptions in the same millisecond, if and when there are failures caused by race conditions.

强调先前评论者提出的观点:如果竞争条件导致失败,您可能会在相同的毫秒内获得多个例外。

#5


If this is an ASP.NET application, then you should look into ASP.NET Health Monitoring. Even by default, it will emit detailed traces into the event log. You can configure it to produce the same output in XML files, and add your own tracing as well.

如果这是一个ASP.NET应用程序,那么您应该查看ASP.NET运行状况监视。即使默认情况下,它也会在事件日志中发出详细的跟踪信息。您可以将其配置为在XML文件中生成相同的输出,并添加自己的跟踪。

#6


Send out an email including the error message and error number is a more efficient way, can't expect end user to report every fail they found. But emails will get all the fails. It's easy for SAP or Ariba to send out an email at some point.

发送包含错误消息和错误号的电子邮件是一种更有效的方式,不能指望最终用户报告他们发现的每个失败。但电子邮件将全部失败。 SAP或Ariba很容易在某个时候发送电子邮件。