static internal ApplicationCrashedEventArgs InitOnce()
 {
     lock( _lock )
     {
         if( _oneCrashOnly != null ) return null;
         return _oneCrashOnly = new ApplicationCrashedEventArgs( CrashLogManager.CreateNew() );
     }
 }
Ejemplo n.º 2
0
 static internal ApplicationCrashedEventArgs InitOnce()
 {
     lock ( _lock )
     {
         if (_oneCrashOnly != null)
         {
             return(null);
         }
         return(_oneCrashOnly = new ApplicationCrashedEventArgs(CrashLogManager.CreateNew()));
     }
 }
Ejemplo n.º 3
0
        private static void RaiseApplicationCrashedEvent()
        {
            var h = ApplicationCrashed;

            if (h != null)
            {
                using (var e = ApplicationCrashedEventArgs.InitOnce())
                {
                    Delegate[] all = h.GetInvocationList();
                    foreach (Delegate d in all)
                    {
                        try
                        {
                            d.DynamicInvoke(null, e);
                        }
                        catch (Exception ex)
                        {
                            e.CrashLog.Writer.WriteLine();
                            e.CrashLog.Writer.WriteLine("== Exception in ApplicationCrashed handling: Type={0}", d.Method.DeclaringType.AssemblyQualifiedName);
                            e.CrashLog.WriteException(ex);
                            e.CrashLog.Writer.WriteLine("== End of Exception in ApplicationCrashed handling");
                        }
                    }
                    if (e.CrashLog.IsValid)
                    {
                        e.CrashLog.Writer.WriteLine("== Registered Exceptions");
                        if (_registeredExceptions.Count > 0)
                        {
                            foreach (string oEx in _registeredExceptions)
                            {
                                e.CrashLog.Writer.WriteLine(oEx);
                            }
                        }
                        e.CrashLog.Writer.WriteLine("== End of Registered Exceptions");
                    }
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// This method is registered on <see cref="CK.AppRecovery.ApplicationRecovery.ApplicationCrashed"/> event.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        static internal void OnApplicationCrash(object source, ApplicationCrashedEventArgs e)
        {
            if (_initialized)
            {
                _hierarchy.Root.Log(Level.Fatal, "Application crashes. Appending existing log files into Crash log. Over!", null);
                _hierarchy.Root.RemoveAppender(_roller);
                _roller.Close();

                if (e.CrashLog.IsValid)
                {
                    char[] buffer = new char[2048];
                    foreach (string f in Directory.GetFiles(_appLogDirectory))
                    {
                        e.CrashLog.Writer.WriteLine("===== Log file: {0} =====", Path.GetFileName(f));
                        try
                        {
                            using (StreamReader r = File.OpenText(f))
                            {
                                int nbRead;
                                while ((nbRead = r.ReadBlock(buffer, 0, buffer.Length)) > 0)
                                {
                                    e.CrashLog.Writer.Write(buffer, 0, nbRead);
                                }
                            }
                        }
                        finally
                        {
                            e.CrashLog.Writer.WriteLine("===== End of log file: {0} =====", Path.GetFileName(f));
                        }
                    }
                }
            }
            else
            {
                e.CrashLog.Writer.WriteLine("CommonLogger has not been initialized.");
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// This method is registered on <see cref="CK.AppRecovery.ApplicationRecovery.ApplicationCrashed"/> event.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        internal static void OnApplicationCrash( object source, ApplicationCrashedEventArgs e )
        {
            if( _initialized )
            {
                _hierarchy.Root.Log( Level.Fatal, "Application crashes. Appending existing log files into Crash log. Over!", null );
                _hierarchy.Root.RemoveAppender( _roller );
                _roller.Close();

                if( e.CrashLog.IsValid )
                {
                    char[] buffer = new char[2048];
                    foreach( string f in Directory.GetFiles( _appLogDirectory ) )
                    {
                        e.CrashLog.Writer.WriteLine( "===== Log file: {0} =====", Path.GetFileName( f ) );
                        try
                        {
                            using( StreamReader r = File.OpenText( f ) )
                            {
                                int nbRead;
                                while( (nbRead = r.ReadBlock( buffer, 0, buffer.Length )) > 0 )
                                {
                                    e.CrashLog.Writer.Write( buffer, 0, nbRead );
                                }
                            }
                        }
                        finally
                        {
                            e.CrashLog.Writer.WriteLine( "===== End of log file: {0} =====", Path.GetFileName( f ) );
                        }
                    }
                }
            }
            else
            {
                e.CrashLog.Writer.WriteLine( "CommonLogger has not been initialized." );
            }
        }