Click or drag to resize

ErrorLogger Class

Represents a logger that can be used for logging handled as well as unhandled exceptions across multiple application types (Windows Application, Console Application, Windows Service, Web Application, Web Service).
Inheritance Hierarchy
SystemObject
  SystemMarshalByRefObject
    System.ComponentModelComponent
      GSF.ErrorManagementErrorLogger
        GSF.Windows.ErrorManagementErrorLogger

Namespace: GSF.Windows.ErrorManagement
Assembly: GSF.Windows (in GSF.Windows.dll) Version: 2.4.218-beta
Syntax
[ToolboxBitmapAttribute(typeof(ErrorLogger))]
public class ErrorLogger : ErrorLogger
View Source

The ErrorLogger type exposes the following members.

Constructors
 NameDescription
Public methodErrorLogger Initializes a new instance of the ErrorLogger class.
Top
Properties
 NameDescription
Public propertyCode exampleActionTextMethod 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.
(Inherited from ErrorLogger)
Public propertyApplicationName Gets the name of the currently executing application.
(Inherited from ErrorLogger)
Public propertyApplicationType Gets the type of the currently executing application.
(Inherited from ErrorLogger)
Protected propertyCanRaiseEventsGets a value indicating whether the component can raise an event.
(Inherited from Component)
Public propertyContactEmail 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.
(Inherited from ErrorLogger)
Public propertyContactName Gets or sets the name of the person who can be contacted by the end-user in case of an Exception.
(Inherited from ErrorLogger)
Public propertyContactPhone Gets or sets the phone number that can be used by the end-user to communicate about an encountered Exception.
(Inherited from ErrorLogger)
Public propertyContainerGets the IContainer that contains the Component.
(Inherited from Component)
Public propertyDatabaseLogSize Gets or sets the maximum exception log size to maintain when logging exceptions to the database.
(Inherited from ErrorLogger)
Protected propertyDesignModeGets a value that indicates whether the Component is currently in design mode.
(Inherited from Component)
Public propertyEnabled Gets or sets a boolean value that indicates whether the ErrorLogger object is currently enabled.
(Inherited from ErrorLogger)
Public propertyErrorLog Get the LogFile object used for logging Exception information to a file.
(Inherited from ErrorLogger)
Public propertyCode exampleErrorTextMethod Gets or sets the Delegate that provides common text stating what could have possibly caused the Exception.
(Inherited from ErrorLogger)
Protected propertyEventsGets the list of event handlers that are attached to this Component.
(Inherited from Component)
Public propertyExitOnUnhandledException Gets or sets a boolean value that indicates whether the application will terminate after logging an unhandled Exception.
(Inherited from ErrorLogger)
Public propertyHandleUnhandledException 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.
(Inherited from ErrorLogger)
Public propertyIsDisposed Gets a flag that indicates whether the object has been disposed.
(Inherited from ErrorLogger)
Public propertyLastException Get the last encountered Exception.
(Inherited from ErrorLogger)
Public propertyLoggers Gets a list of methods registered for logging information about an encountered Exception.
(Inherited from ErrorLogger)
Public propertyLogToDatabase Gets or sets a boolean value that indicates whether Exception information is to be written to the database.
(Inherited from ErrorLogger)
Public propertyLogToEmail Gets or sets a boolean value that indicates whether Exception information is to be sent in an e-mail to the ContactEmail address.
(Inherited from ErrorLogger)
Public propertyLogToEventLog Gets or sets a boolean value that indicates whether Exception information is to be written to the EventLog.
(Inherited from ErrorLogger)
Public propertyLogToFile Gets or sets a boolean value that indicates whether Exception information is to be written to the ErrorLog.
(Inherited from ErrorLogger)
Public propertyLogToScreenshot Gets or sets a boolean value that indicates whether a screenshot of the user's desktop is to be taken when an Exception is logged.
Public propertyLogToUI Gets or sets a boolean value that indicates whether Exception information is to be displayed on the application UI.
(Inherited from ErrorLogger)
Public propertyLogUserInfo 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.
(Inherited from ErrorLogger)
Public propertyMoreInfoTextMethod Gets or sets the Delegate that provides text containing detailed information about the encountered Exception.
(Inherited from ErrorLogger)
Public propertyName Gets the unique identifier of the ErrorLogger object.
(Inherited from ErrorLogger)
Public propertyPersistSettings Gets or sets a boolean value that indicates whether the settings of ErrorLogger object are to be saved to the config file.
(Inherited from ErrorLogger)
Public propertyCode exampleScopeTextMethod Gets or sets the Delegate that provides text stating what is going to happen as a result of the Exception.
(Inherited from ErrorLogger)
Public propertySettingsCategory 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.
(Inherited from ErrorLogger)
Public propertySiteGets or sets the ISite of the Component.
(Inherited from Component)
Public propertySmtpServer Gets or sets the SMTP server to be used for sending e-mail messages containing Exception information to the ContactEmail address.
(Inherited from ErrorLogger)
Public propertyStatus Gets the descriptive status of the ErrorLogger object.
(Overrides ErrorLoggerStatus)
Public propertySuppressInteractiveLogging 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.
(Inherited from ErrorLogger)
Top
Methods
 NameDescription
Public methodBeginInit Performs necessary operations before the ErrorLogger object properties are initialized.
(Inherited from ErrorLogger)
Public methodCreateObjRefCreates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.
(Inherited from MarshalByRefObject)
Public methodDisposeReleases all resources used by the Component.
(Inherited from Component)
Protected methodDispose(Boolean) Releases the unmanaged resources used by the ErrorLogger object and optionally releases the managed resources.
(Inherited from ErrorLogger)
Public methodEndInit Performs necessary operations after the ErrorLogger object properties are initialized.
(Inherited from ErrorLogger)
Public methodEqualsDetermines whether the specified object is equal to the current object.
(Inherited from Object)
Protected methodExceptionToDatabase Logs encountered Exception to the database.
(Inherited from ErrorLogger)
Protected methodExceptionToEmail Logs encountered Exception to an e-mail message.
(Inherited from ErrorLogger)
Protected methodExceptionToEventLog Logs encountered Exception to the EventLog.
(Inherited from ErrorLogger)
Protected methodExceptionToFile Logs encountered Exception to the ErrorLog.
(Inherited from ErrorLogger)
Protected methodExceptionToScreenshot Takes a screenshot of the user's desktop when the Exception is encountered.
Protected methodExceptionToUI Logs encountered Exception to the application UI.
(Inherited from ErrorLogger)
Protected methodExceptionToWebPage Shows Exception information in a Web Site.
(Inherited from ErrorLogger)
Protected methodExceptionToWindowsCui Shows Exception information in a Console Application.
(Inherited from ErrorLogger)
Protected methodExceptionToWindowsGui Shows Exception information in a Windows Application.
(Overrides ErrorLoggerExceptionToWindowsGui)
Protected methodFinalizeReleases unmanaged resources and performs other cleanup operations before the Component is reclaimed by garbage collection.
(Inherited from Component)
Protected methodGetEmailAttachments Gets or sets the comma-separated or semicolon-separated list of file names to be attached to the Mail message.
(Overrides ErrorLoggerGetEmailAttachments)
Protected methodGetExtendedMoreInfoText Allows other loggers to extend "more info text".
(Overrides ErrorLoggerGetExtendedMoreInfoText(String))
Public methodGetHashCodeServes as the default hash function.
(Inherited from Object)
Public methodGetLifetimeServiceRetrieves the current lifetime service object that controls the lifetime policy for this instance.
(Inherited from MarshalByRefObject)
Protected methodGetMoreInfoText Default Delegate for MoreInfoTextMethod.
(Inherited from ErrorLogger)
Protected methodGetServiceReturns an object that represents a service provided by the Component or by its Container.
(Inherited from Component)
Public methodGetTypeGets the Type of the current instance.
(Inherited from Object)
Public methodInitialize Initializes the ErrorLogger object.
(Inherited from ErrorLogger)
Public methodInitializeLifetimeServiceObtains a lifetime service object to control the lifetime policy for this instance.
(Inherited from MarshalByRefObject)
Public methodLoadSettings Loads saved settings for the ErrorLogger object from the config file if the PersistSettings property is set to true.
(Overrides ErrorLoggerLoadSettings)
Public methodLog(Exception) Logs information about the encountered Exception.
(Inherited from ErrorLogger)
Public methodLog(Exception, Boolean) Logs information about the encountered Exception.
(Inherited from ErrorLogger)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object.
(Inherited from Object)
Protected methodMemberwiseClone(Boolean)Creates a shallow copy of the current MarshalByRefObject object.
(Inherited from MarshalByRefObject)
Protected methodOnLoggingException Raises the LoggingException event.
(Inherited from ErrorLogger)
Protected methodRegister Registers the ErrorLogger object to handle unhandled Exception if the HandleUnhandledException property is set to true.
(Overrides ErrorLoggerRegister)
Public methodSaveSettings Saves settings for the ErrorLogger object to the config file if the PersistSettings property is set to true.
(Overrides ErrorLoggerSaveSettings)
Public methodToStringReturns a String containing the name of the Component, if any. This method should not be overridden.
(Inherited from Component)
Protected methodUnregister Unregister the ErrorLogger object from handling unhandled Exception.
(Overrides ErrorLoggerUnregister)
Top
Events
 NameDescription
Public eventDisposedOccurs when the component is disposed by a call to the Dispose method.
(Inherited from Component)
Public eventLoggingException Occurs when an Exception is encountered while logging an Exception.
(Inherited from ErrorLogger)
Top
Fields
 NameDescription
Public fieldStatic memberDefaultLogToScreenshot Specifies the default value for the LogToScreenshot property.
Top
Extension Methods
 NameDescription
Public Extension MethodGetEnumValueOrDefault Gets the enumeration constant for value, if defined in the enumeration, or a default value.
(Defined by EnumExtensions)
Public Extension MethodGetEnumValueOrDefaultT Gets the enumeration constant for this value, if defined in the enumeration, or a default value.
(Defined by EnumExtensions)
Top
Example
This example shows how to use the ErrorLogger component to log handled and unhandled exceptions:
C#
using System;
using System.IO;
using GSF.Windows.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.LogToScreenshot = true;            // Take a screenshot of desktop on exception.
        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();
    }
}
See Also