日期:2008-05-30  浏览次数:20371 次

        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 );