Errors are inevitable during system development. But how can we handle errors and collect as much information as possible to analyze errors, it is very helpful to find and eliminate errors. The following provides an error information collection class for you, hoping to be useful.
/// <Summary>
/// Class that handles gathering of error information
/// For reporting purposes
/// </Summary>
Public static class ErrorManager
{
# Region Public Static Functions
/// <Summary>
/// Returns information specific to ASP. Net/IIS (Request, Response, Cache, etc .)
/// </Summary>
/// <Returns> An HTML formatted string containing the ASP. Net information </returns>
Public static string GetAllASPNetInformation ()
{
StringBuilder Builder = new StringBuilder ();
HttpContext Current = HttpContext. Current;
Builder. Append ("<strong> Request Variables </strong> <br/> ");
Builder. Append (Current. Request. DumpRequestVariable ());
Builder. Append ("<br/> <strong> Response Variables </strong> <br/> ");
Builder. Append (Current. Response. DumpResponseVariable ());
Builder. Append ("<br/> <strong> Server Variables </strong> <br/> ");
Builder. Append (Current. Request. DumpServerVars ());
Builder. Append ("<br/> <strong> Session Variables </strong> <br/> ");
Builder. Append (Current. Session. DumpSession ());
Builder. Append ("<br/> <strong> Cookie Variables </strong> <br/> ");
Builder. Append (Current. Request. Cookies. DumpCookies ());
Builder. Append ("<br/> <strong> Cache Variables </strong> <br/> ");
Builder. Append (Current. Cache. DumpCache ());
Builder. Append ("<br/> <strong> Application State Variables </strong> <br/> ");
Builder. Append (Current. Application. DumpApplicationState ());
Return Builder. ToString ();
}
/// <Summary>
/// Gets assembly information for all currently loaded assemblies
/// </Summary>
/// <Returns> An HTML formatted string containing the assembly information </returns>
Public static string GetAssemblyInformation ()
{
StringBuilder Builder = new StringBuilder ();
Builder. Append ("<strong> Assembly Information </strong> <br/> ");
AppDomain. CurrentDomain. GetAssemblies (). ForEach <Assembly> (x => Builder. Append (x. DumpProperties ()));
Return Builder. ToString ();
}
/// <Summary>
/// Gets information about the system.
/// </Summary>
/// <Returns> An HTML formatted string containing the state of the system. </returns>
Public static string GetSystemInformation ()
{
StringBuilder Builder = new StringBuilder ();
Builder. Append ("<strong> System Information </strong> <br/> ");
Builder. Append (System. Type. GetType ("Utilities. Environment. Environment"). DumpProperties ());
Return Builder. ToString ();
}
/// <Summary>
/// Gets all process information and outputs it to an HTML formatted string
/// </Summary>
/// <Returns> An HTML formatted string containing the process information </returns>
Public static string GetProcessInformation ()
{
StringBuilder Builder = new StringBuilder ();
Builder. Append ("<strong> Process Information </strong> <br/> ");
Builder. Append (Process. GetProcesses (). GetInformation ());
Return Builder. ToString ();
}
# Endregion
}
From weizhiai12's column