This class is the concrete implementation class that writes error information to the system log, which inherits from Abstracthandleclass. Users can customize the error-handling method by imitating the class. The specific code is as follows:
public class Errhdleventlogclass:abstracthandleclass
{
public const int ID = 2; Number of error-handling methods
Public Errhdleventlogclass ()
{
//
Todo:add constructor Logic here
//
}
Overloaded the method of the parent class to implement the processing action of the error message
public override int HandleError (Errormsgclass emsg)
{
if (this. Handleflag (Emsg,id))//judge whether to handle
{
Try
{
EventLog el = new EventLog ();
El. Source = emsg.hash["Eventlogsource"]. ToString ();
El. WriteEntry (FMT. Format (emsg), EventLogEntryType.Error);
return 0;
}
Catch
{
return 1; Processing failed
}
}
Else
{
return 9999; The user did not select this method of processing
}
}
}
Errhdlmailclass:
This class is a concrete implementation class that sends error messages through mail. The specific code is as follows:
public class Errhdlmailclass:abstracthandleclass
{
public const int ID = 5;
Public Errhdlmailclass ()
{
//
Todo:add constructor Logic here
//
}
public override int HandleError (Errormsgclass emsg)
This paper introduces an implementation model of error handling mechanism in polling mode. The advantage of this mechanism is that two aspects of error handling can be customized through inheritance. One is the method of error handling, common methods are to write system log, send mail, write log file, pop-up error message box, write database, etc. The mechanism can be designed in advance to allow users to choose (multiple choices), if the user wants the method is not defined, the user must inherit Abstracthandleclass, you can design the wrong way of handling. The second is the format of the error message, if the user is not accustomed to the default error message output format, then inherit Abstractmessageformatclass, you can customize the error message output format and content.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.