Esempio n. 1
0
        public static void 初始化(TraceEventType __日志级别 = TraceEventType.Verbose, string __日志目录 = "日志", string __日志文件名称 = "", int __保留天数 = 30)
        {
            if (_已初始化)
            {
                return;
            }
            _已初始化 = true;

            H日志.初始化(__日志级别, __日志目录, __日志文件名称);
            日志目录 = __日志目录;

            var __环境信息 = new Dictionary <string, object>();

            __环境信息["Version"]          = Assembly.GetCallingAssembly().GetName().Version.ToString();
            __环境信息["FileVersion"]      = FileVersionInfo.GetVersionInfo(Assembly.GetCallingAssembly().Location).FileVersion;
            __环境信息["MachineName"]      = Environment.MachineName;
            __环境信息["UserName"]         = Environment.UserName;
            __环境信息["IP"]               = String.Join(";", H网络配置.获取可用IP().Select(q => q.ToString()));
            __环境信息["OSVersion"]        = Environment.OSVersion.VersionString;
            __环境信息["CLR Version"]      = Environment.Version;
            __环境信息["Is64BitProcess"]   = Environment.Is64BitProcess;
            __环境信息["CurrentDirectory"] = Environment.CurrentDirectory;
            记录提示("程序启动", H序列化.ToJSON字符串(__环境信息));

            if (__保留天数 != int.MaxValue)
            {
                清除过期调试文件(日志目录, __保留天数);
            }

            if (处理异常)
            {
                Application.ThreadException += (sender, ex) => H异常.处理UI线程(ex.Exception, 未处理异常自动退出);
                AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
                {
                    if (e.ExceptionObject == null)
                    {
                        return;
                    }
                    var ex = e.ExceptionObject as Exception;
                    if (ex == null)
                    {
                        记录致命(e.ExceptionObject.ToString());
                    }
                    else
                    {
                        H异常.处理非UI线程(ex);
                    }
                };
            }
        }
Esempio n. 2
0
        public static void 初始化(bool __处理异常 = true, bool __清除过期日志 = true, int __保留天数 = 7)
        {
            if (_已初始化)
            {
                return;
            }
            _已初始化 = true;

            if (__清除过期日志)
            {
                清除过期调试文件("日志", __保留天数);
            }
            配置日志文件输出();
            var __环境信息 = new Dictionary <string, object>();

            __环境信息["Version".PadRight(20)]          = Assembly.GetCallingAssembly().GetName().Version.ToString();
            __环境信息["FileVersion".PadRight(20)]      = FileVersionInfo.GetVersionInfo(Assembly.GetCallingAssembly().Location).FileVersion;
            __环境信息["MachineName".PadRight(20)]      = Environment.MachineName;
            __环境信息["UserName".PadRight(20)]         = Environment.UserName;
            __环境信息["IP".PadRight(20)]               = String.Join(";", H网络配置.获取可用IP().Select(q => q.ToString()));
            __环境信息["OSVersion".PadRight(20)]        = Environment.OSVersion.VersionString;
            __环境信息["CLR Version".PadRight(20)]      = Environment.Version;
            __环境信息["Is64BitProcess".PadRight(20)]   = Environment.Is64BitProcess;
            __环境信息["CurrentDirectory".PadRight(20)] = Environment.CurrentDirectory;
            记录提示("程序启动", __环境信息);
            if (__处理异常)
            {
                Application.ThreadException += (sender, ex) => H异常.处理UI线程(ex.Exception);
                AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
                {
                    if (e.ExceptionObject == null)
                    {
                        return;
                    }
                    var ex = e.ExceptionObject as Exception;
                    if (ex == null)
                    {
                        记录致命(e.ExceptionObject.ToString());
                    }
                    else
                    {
                        H异常.处理非UI线程(ex);
                    }
                };
            }
        }