分享一个收集系统出现错误时收集信息的类

在系统开发过程中,出现错误在所难免,但是怎么样处理好出错的情况,以及尽可能地收集出错时的一些信息,对我们分析错误,从而查找排除错误是很有帮助的,下面提供一个错误信息收集类给大家,希望能够派上用场。

/// <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 /><br /><strong>Response Variables</strong><br />");
            Builder.Append(Current.Response.DumpResponseVariable());
            Builder.Append("<br /><br /><strong>Server Variables</strong><br />");
            Builder.Append(Current.Request.DumpServerVars());
            Builder.Append("<br /><br /><strong>Session Variables</strong><br />");
            Builder.Append(Current.Session.DumpSession());
            Builder.Append("<br /><br /><strong>Cookie Variables</strong><br />");
            Builder.Append(Current.Request.Cookies.DumpCookies());
            Builder.Append("<br /><br /><strong>Cache Variables</strong><br />");
            Builder.Append(Current.Cache.DumpCache());
            Builder.Append("<br /><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
    }



转载于:https://www.cnblogs.com/kevinGao/archive/2012/01/07/2323350.html

  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 扫一扫,分享海报

表情包
插入表情
评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符
©️2022 CSDN 皮肤主题:编程工作室 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值