一段log execption 的代码

来源:互联网 发布:shadow defender 知乎 编辑:程序博客网 时间:2024/05/18 19:21
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
        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();共2页: 上一页 1 [2] 下一页 <script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
原创粉丝点击