一段log execption 的代码

        static public string WriteExceptionRecord( Exception e ) {
            try {
                string    fileName = Path.Combine( Application.StartupPath, "error.log" );
                StreamWriter sw = new StreamWriter( fileName, true );
            
                sw.WriteLine( "ErrorLog.WriteExceptionLog() >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" );

                try {
                    DateTime now = DateTime.Now;
                    sw.WriteLine( "CurrentDate: " + now.ToLongDateString() );
                    sw.WriteLine( "CurrentTime: " + now.ToLongTimeString() );
                    sw.Flush();
                }
                catch( Exception ex ) {
                    sw.WriteLine( "<error-CurrentDateTime>" + ex.ToString() );
                }
                
                try {
                    sw.WriteLine( "Exception.Type: " + e.GetType().Name );
                    sw.WriteLine( "Exception.Message: " + e.Message );
                    sw.WriteLine( "Exception.Source: " + e.Source );
                    sw.WriteLine( "Exception.HelpLink: " + e.HelpLink );
                    sw.WriteLine( "Exception.TargetSite: " + e.TargetSite );
                    sw.WriteLine( "Exception.StackTrace: " );
                    sw.WriteLine( e.StackTrace );
                    sw.Flush();
                }
                catch( Exception ex ) {
                    sw.WriteLine( "<error-Exception>" + ex.ToString() );
                }
        
                try {
                    sw.WriteLine( "GC.TotalMemory: " + GC.GetTotalMemory( false ) );
                    sw.Flush();
                }
                catch( Exception ex ) {
                    sw.WriteLine( "<error-GC>" + ex.ToString() );
                }
        
                try {
                    sw.WriteLine( "Application.ProductName: " + Application.ProductName );
                    sw.WriteLine( "Application.ProductVersion: " + Application.ProductVersion );
                    sw.WriteLine( "Application.StartupPath: " + Application.StartupPath );
                    sw.WriteLine( "Application.ExecutablePath: " + Application.ExecutablePath );
                    sw.WriteLine( "Application.CurrentDirectory: " + Directory.GetCurrentDirectory() );
                    sw.Flush();
                }
                catch( Exception ex ) {
                    sw.WriteLine( "<error-Application>" + ex.ToString() );
                }
        
                try {
                    Assembly execAssembly = Assembly.GetExecutingAssembly();
                    sw.WriteLine( "ExecutingAssembly.CodeBase: " + execAssembly.CodeBase );
                    sw.WriteLine( "ExecutingAssembly.Location: " + execAssembly.Location );
                    sw.WriteLine( "ExecutingAssembly.GlobalAssemblyCache: " + execAssembly.GlobalAssemblyCache );
                    sw.Flush();
                }
                catch( Exception ex ) {
                    sw.WriteLine( "<error-ExecutingAssembly>" + ex.ToString() );
                }

                try {
                    foreach( string watchName in s_htWatches.Keys ) {
                        sw.WriteLine( "Watch[" + watchName + "]: " + GetWatchString( watchName ) );
                    }
                    sw.Flush();
                }
                catch( Exception ex ) {
                    sw.WriteLine( "<error-Watches>" + ex.ToString() );
                }

                try {
                    foreach( LogEntry logEntry in s_logEntries ) {
                        sw.WriteLine( "LogEntry" + logEntry.ToString() );
                    }
                    sw.Flush();
                }
                catch( Exception ex ) {
                    sw.WriteLine( "<error-LogEntry>" + ex.ToString() );
                }
                
                try {
                    Assembly selfAssembly = Assembly.GetAssembly( typeof( BugTracking ) );
                    sw.WriteLine( "CurrentAssembly.CodeBase: " + selfAssembly.CodeBase );
                    sw.WriteLine( "CurrentAssembly.Location: " + selfAssembly.Location );
                    sw.WriteLine( "CurrentAssembly.GlobalAssemblyCache: " + selfAssembly.GlobalAssemblyCache );
                    sw.Flush();
                }
                catch( Exception ex ) {
                    sw.WriteLine( "<error-CurrentAssembly>" + ex.ToString() );
                }
                
                try {
                    Thread thread = Thread.CurrentThread;
                    sw.WriteLine( "CurrentThread.Name: " + thread.Name );
                    sw.WriteLine( "CurrentThread.Priority: " + thread.Priority );
                    sw.Flush();
                }
                catch( Exception ex ) {
                    sw.WriteLine( "<error-CurrentThread>" + ex.ToString() );
                }

                try {
                    Process process = Process.GetCurrentProcess();
                    sw.WriteLine( "CurrentProcess.Name: " + process.ProcessName );
                    sw.WriteLine( "CurrentProcess.MachineName: " + process.MachineName );
                    sw.WriteLine( "CurrentProcess.MainModule: " + process.MainModule );
                    sw.WriteLine( "CurrentProcess.StartDate: " + process.StartTime.ToLongDateString() );
                    sw.WriteLine( "CurrentProcess.StartTime: " + process.StartTime.ToLongTimeString() );
                    sw.WriteLine( "CurrentProcess.UserProcessorTime: " + process.UserProcessorTime );
                    sw.WriteLine( "CurrentProcess.TotalProcessorTime: " + process.TotalProcessorTime );
                    sw.Flush();
                }
                catch( Exception ex ) {
                    sw.WriteLine( "<error-CurrentProcess>" + ex.ToString() );
                }

                try {
                    OperatingSystem os = Environment.OSVersion;
                    sw.WriteLine( "Environment.OSVersion.Platform: " + os.Platform );
                    sw.WriteLine( "Environment.OSVersion.Version: " + os.Version );
    
                    Version ver = Environment.Version;
                    sw.WriteLine( "Environment.Version.Major: " + ver.Major );
                    sw.WriteLine( "Environment.Version.Minor: " + ver.Minor );
                    sw.WriteLine( "Environment.Version.Revision: " + ver.Revision );
                    sw.WriteLine( "Environment.Version.Build: " + ver.Build );

                    sw.WriteLine( "Environment.UserName: " + Environment.UserName );
                    sw.WriteLine( "Environment.SystemDirectory: " + Environment.SystemDirectory );
                    sw.WriteLine( "Environment.TickCount: " + Environment.TickCount );
                    sw.WriteLine( "Environment.CommandLine: " + Environment.CommandLine );
                    sw.WriteLine( "Environment.WorkingSet: " + Environment.WorkingSet );
                    string[] args = Environment.GetCommandLineArgs();
                    if( args != null ) {
                        for( int i = 0; i < args.Length; i ++ ) {
                            sw.WriteLine( "Environment.CommandLineArgs[" + i + "]: " + args[i] );
                        }
                    }
                    sw.WriteLine( "Environment.StackTrace: " );
                    sw.WriteLine( Environment.StackTrace );
                    sw.Flush();
                }
                catch( Exception ex ) {
                    sw.WriteLine( "<error-Environment>" + ex.ToString() );
                }

                sw.WriteLine( "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" );
                sw.Close();
                
                return    fileName;
            }
            catch( Exception ) {
                return    "-- error writing log file --";
            }
        }

时间: 2024-11-08 22:18:49

一段log execption 的代码的相关文章

android-一段很简单的代码 Eclipse没有报错 可是手机上一点按钮就意外停止

问题描述 一段很简单的代码 Eclipse没有报错 可是手机上一点按钮就意外停止 (http://img.ask.csdn.net/upload/201505/31/1433054546_331226.png) 和书上对比了好多次了-.- 第一个 ```package com.example.ex04_01; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import a

9段PHP实用功能的代码推荐_php技巧

一.查看邮件是否已被阅读 当你在发送邮件时,你或许很想知道该邮件是否被对方已阅读.这里有段非常有趣的代码片段能够显示对方IP地址记录阅读的实际日期和时间. 复制代码 代码如下: <? error_reporting(0); Header("Content-Type: image/jpeg");   //Get IP if (!empty($_SERVER['HTTP_CLIENT_IP'])) {   $ip=$_SERVER['HTTP_CLIENT_IP']; } elsei

一段导出数据库的代码

导出数据|数据库 一段导出数据库的代码  <?//$dbname="mytest";$filename="file.sql";mysql_pconnect ("localhost:3306","root","");//function sqldumptable($table) {global $DB_site;$tabledump = "DROP TABLE IF EXISTS $table

电脑-网页加了一段53客服代码之后,网页在手机浏览器上显示会放的很大。

问题描述 网页加了一段53客服代码之后,网页在手机浏览器上显示会放的很大. 就是这段53客服代码 我把它加到网页的最底部,电脑上浏览网页是没有问题的,正常显示.但是在手机浏览器上看网页就被强制放大,而且不能把网页缩到最小(适合手机屏幕大小显示).请问怎么解决?跪求各位大神.

java源码-求这段c语言的代码换成java的代码

问题描述 求这段c语言的代码换成java的代码 #include #define P 3.1415927#define toFeet(x) x/12.0#define toMiles(x) x/5280.0int main(){ double diameter;//直径 int revolutions;//转数 double time;//香蕉 double s; int count=1; while(scanf("%lf%d%lf",&diameter,&revolu

vba-请各位看看这段vb.net的代码,是操作word的

问题描述 请各位看看这段vb.net的代码,是操作word的 Public Sub Textbox1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown If e.KeyCode = Keys.Enter Then Dim p As String = InputBox("请输入") Dim WDAPP As Object

这段java for循环代码的结果怎么不对呢?DOS 输出结果为800.0,编译也没有啥问题啊。

问题描述 这段java for循环代码的结果怎么不对呢?DOS 输出结果为800.0,编译也没有啥问题啊. 如题,代码如下: public class Example41_3 { public static void main(String args[]){ float i=0; double sum=0; for(i=1;i<=3;i++); { sum+=8*(Math.pow(10.0,(i-1))); } System.out.println("计算8+88+888+8888+--

求大神帮忙,一段关于mui的代码

问题描述 求大神帮忙,一段关于mui的代码 请问下下面这串代码说的大概是什么意思, (function($, window, document, undefined) { $.init(); var qsa = function() { return [].slice.call(document.querySelectorAll.apply(document, arguments)); }; console.info(qsa("[_src]")+"n"+99) qs

java-请教大家一段查找素数的代码

问题描述 请教大家一段查找素数的代码 #include<iostream> #include<cmath> using namespace std; bool Jude(int n) { int i; if(n==2||n==3) return true; else if(n<2) return false; else { for(i=2;i<=sqrt(1.0*n);i++)//这里sqrt(1.0*n)就算了一次, //如果判断条件改为i*i<=n,这里的i*