Error
|
[ToolboxBitmapAttribute(typeof(ErrorLogger))] public class ErrorLogger : Component, ISupportLifecycle, IDisposable, ISupportInitialize, IProvideStatus, IPersistSettings
The ErrorLogger type exposes the following members.
Name | Description | |
---|---|---|
ErrorLogger | Initializes a new instance of the ErrorLogger class. | |
ErrorLogger(IContainer) | Initializes a new instance of the ErrorLogger class. |
Name | Description | |
---|---|---|
ActionTextMethod | Gets or sets the Delegate that provides text stating the action(s) that can be taken by the end-user after an Exception is encountered. | |
ApplicationName | Gets the name of the currently executing application. | |
ApplicationType | Gets the type of the currently executing application. | |
CanRaiseEvents | Gets a value indicating whether the component can raise an event. (Inherited from Component) | |
ContactEmail | Gets or sets the e-mail address where e-mail messages containing Exception information are to be sent when the LogToEmail property is set to true. | |
ContactName | Gets or sets the name of the person who can be contacted by the end-user in case of an Exception. | |
ContactPhone | Gets or sets the phone number that can be used by the end-user to communicate about an encountered Exception. | |
Container | Gets the IContainer that contains the Component. (Inherited from Component) | |
DatabaseLogSize | Gets or sets the maximum exception log size to maintain when logging exceptions to the database. | |
DesignMode | Gets a value that indicates whether the Component is currently in design mode. (Inherited from Component) | |
Enabled | Gets or sets a boolean value that indicates whether the ErrorLogger object is currently enabled. | |
ErrorLog | Get the LogFile object used for logging Exception information to a file. | |
ErrorTextMethod | Gets or sets the Delegate that provides common text stating what could have possibly caused the Exception. | |
Events | Gets the list of event handlers that are attached to this Component. (Inherited from Component) | |
ExitOnUnhandledException | Gets or sets a boolean value that indicates whether the application will terminate after logging an unhandled Exception. | |
HandleUnhandledException | Gets or sets a boolean value that indicates whether the ErrorLogger object must register itself to handle Exception that are not trapped inside of a try-catch block. | |
IsDisposed | Gets a flag that indicates whether the object has been disposed. | |
LastException | Get the last encountered Exception. | |
Loggers | Gets a list of methods registered for logging information about an encountered Exception. | |
LogToDatabase | Gets or sets a boolean value that indicates whether Exception information is to be written to the database. | |
LogToEmail | Gets or sets a boolean value that indicates whether Exception information is to be sent in an e-mail to the ContactEmail address. | |
LogToEventLog | Gets or sets a boolean value that indicates whether Exception information is to be written to the EventLog. | |
LogToFile | Gets or sets a boolean value that indicates whether Exception information is to be written to the ErrorLog. | |
LogToUI | Gets or sets a boolean value that indicates whether Exception information is to be displayed on the application UI. | |
LogUserInfo | Gets or sets a boolean value that indicates whether information about local user (for windows applications) or remote user (for web applications) is to be logged when logging an Exception. | |
MoreInfoTextMethod | Gets or sets the Delegate that provides text containing detailed information about the encountered Exception. | |
Name | Gets the unique identifier of the ErrorLogger object. | |
PersistSettings | Gets or sets a boolean value that indicates whether the settings of ErrorLogger object are to be saved to the config file. | |
ScopeTextMethod | Gets or sets the Delegate that provides text stating what is going to happen as a result of the Exception. | |
SettingsCategory | Gets or sets the category under which the settings of ErrorLogger object are to be saved to the config file if the PersistSettings property is set to true. | |
Site | Gets or sets the ISite of the Component. (Inherited from Component) | |
SmtpServer | Gets or sets the SMTP server to be used for sending e-mail messages containing Exception information to the ContactEmail address. | |
Status | Gets the descriptive status of the ErrorLogger object. | |
SuppressInteractiveLogging | Gets or sets flag that controls if Loggers requiring interaction either directly or indirectly when logging handled Exception using the Log(Exception) method are enabled. |
Name | Description | |
---|---|---|
BeginInit | Performs necessary operations before the ErrorLogger object properties are initialized. | |
CreateObjRef | Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject) | |
Dispose | Releases all resources used by the Component. (Inherited from Component) | |
Dispose(Boolean) |
Releases the unmanaged resources used by the ErrorLogger object and optionally releases the
managed resources.
(Overrides ComponentDispose(Boolean)) | |
EndInit | Performs necessary operations after the ErrorLogger object properties are initialized. | |
Equals | Determines whether the specified object is equal to the current object. (Inherited from Object) | |
ExceptionToDatabase | Logs encountered Exception to the database. | |
ExceptionToEmail | Logs encountered Exception to an e-mail message. | |
ExceptionToEventLog | Logs encountered Exception to the EventLog. | |
ExceptionToFile | Logs encountered Exception to the ErrorLog. | |
ExceptionToUI | Logs encountered Exception to the application UI. | |
ExceptionToWebPage | Shows Exception information in a Web Site. | |
ExceptionToWindowsCui | Shows Exception information in a Console Application. | |
ExceptionToWindowsGui | Shows Exception information in a Windows Application. | |
Finalize | Releases unmanaged resources and performs other cleanup operations before the Component is reclaimed by garbage collection. (Inherited from Component) | |
GetEmailAttachments | Gets or sets the comma-separated or semicolon-separated list of file names to be attached to the Mail message. | |
GetExceptionInfo | Gets information about an Exception complete with system and application information. | |
GetExtendedMoreInfoText | Allows other loggers to extend "more info text". | |
GetHashCode | Serves as the default hash function. (Inherited from Object) | |
GetLifetimeService | Retrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject) | |
GetMoreInfoText | Default Delegate for MoreInfoTextMethod. | |
GetService | Returns an object that represents a service provided by the Component or by its Container. (Inherited from Component) | |
GetType | Gets the Type of the current instance. (Inherited from Object) | |
Initialize | Initializes the ErrorLogger object. | |
InitializeLifetimeService | Obtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject) | |
LoadSettings | Loads saved settings for the ErrorLogger object from the config file if the PersistSettings property is set to true. | |
Log(Exception) | Logs information about the encountered Exception. | |
Log(Exception, Boolean) | Logs information about the encountered Exception. | |
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object) | |
MemberwiseClone(Boolean) | Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject) | |
OnLoggingException | Raises the LoggingException event. | |
Register | Registers the ErrorLogger object to handle unhandled Exception if the HandleUnhandledException property is set to true. | |
SaveSettings | Saves settings for the ErrorLogger object to the config file if the PersistSettings property is set to true. | |
ToString | Returns a String containing the name of the Component, if any. This method should not be overridden. (Inherited from Component) | |
Unregister | Unregister the ErrorLogger object from handling unhandled Exception. |
Name | Description | |
---|---|---|
Disposed | Occurs when the component is disposed by a call to the Dispose method. (Inherited from Component) | |
LoggingException | Occurs when an Exception is encountered while logging an Exception. |
Name | Description | |
---|---|---|
DefaultContactEmail | Specifies the default value for the ContactEmail property. | |
DefaultContactName | Specifies the default value for the ContactName property. | |
DefaultContactPhone | Specifies the default value for the ContactPhone property. | |
DefaultExitOnUnhandledException | Specifies the default value for the ExitOnUnhandledException property. | |
DefaultHandleUnhandledException | Specifies the default value for the HandleUnhandledException property. | |
DefaultLogToDatabase | Specifies the default value for the LogToDatabase property. | |
DefaultLogToEmail | Specifies the default value for the LogToEmail property. | |
DefaultLogToEventLog | Specifies the default value for the LogToEventLog property. | |
DefaultLogToFile | Specifies the default value for the LogToFile property. | |
DefaultLogToUI | Specifies the default value for the LogToUI property. | |
DefaultLogUserInfo | Specifies the default value for the LogUserInfo property. | |
DefaultPersistSettings | Specifies the default value for the PersistSettings property. | |
DefaultSettingsCategory | Specifies the default value for the SettingsCategory property. | |
DefaultSmtpServer | Specifies the default value for the SmtpServer property. |
Name | Description | |
---|---|---|
GetEnumValueOrDefault |
Gets the enumeration constant for value, if defined in the enumeration, or a default value.
(Defined by EnumExtensions) | |
GetEnumValueOrDefaultT |
Gets the enumeration constant for this value, if defined in the enumeration, or a default value.
(Defined by EnumExtensions) |
Adapted from exception handling code by Jeff Atwood of CodingHorror.com. Demo projects for handling unhandled exception in both windows and web environment by Jeff Atwood are available at The Code Project web site. See: http://www.codeproject.com/script/articles/list_articles.asp?userid=450027
Error logger with Windows Forms capabilities can be found in the GSF.Windows assembly.
using System; using System.IO; using GSF.ErrorManagement; class Program { static ErrorLogger s_logger; static Program() { s_logger = new ErrorLogger(); s_logger.LogToUI = true; // Show exception info on the UI. s_logger.LogToFile = true; // Log exception info to a file. s_logger.LogToEmail = true; // Send exception info in an e-mail. s_logger.LogToEventLog = true; // Log exception info to the event log. s_logger.ContactEmail = "dev@email.com"; // Provide an e-mail address. s_logger.HandleUnhandledException = true; // Configure to handle unhandled exceptions. s_logger.PersistSettings = true; // Save settings to the config file. s_logger.Initialize(); // Initialize ErrorLogger component for use. } static void Main(string[] args) { try { // This may cause a handled FileNotFoundException if the file doesn't exist. string data = File.ReadAllText(@"c:\NonExistentFile.txt"); } catch (Exception ex) { // When logging handled exceptions we want to disable loggers (UI logger and E-mail logger) that // may require interaction either directly or indirectly as it can be annoying. All the loggers // are enabled automatically after the handled exception has been logged. s_logger.SuppressInteractiveLogging(); s_logger.Log(ex); } int numerator = 1; int denominator = 0; int result = numerator / denominator; // This will cause an unhandled DivideByZeroException. Console.ReadLine(); } }