CK.Core.SystemActivityMonitor.HandleError C# (CSharp) Method

HandleError() static private method

static private HandleError ( string s ) : void
s string
return void
        static void HandleError( string s )
        {
            string fullLogFilePath = null;
            Exception errorWhileWritingFile = null;
            // Atomically captures the LogPath to use.
            string logPath = _logPath;
            if( logPath != null )
            {
                try
                {
                    fullLogFilePath = FileUtil.WriteUniqueTimedFile( logPath + SubDirectoryName, ".txt", DateTime.UtcNow, Encoding.UTF8.GetBytes( s ), true );
                }
                catch( Exception ex )
                {
                    errorWhileWritingFile = ex;
                }
            }
            var h = OnError;
            if( h != null )
            {
                LowLevelErrorEventArgs e = new LowLevelErrorEventArgs( s, fullLogFilePath, errorWhileWritingFile );
                // h.GetInvocationList() creates an independent copy of Delegate[].
                foreach( EventHandler<LowLevelErrorEventArgs> d in h.GetInvocationList() )
                {
                    try
                    {
                        d( null, e );
                    }
                    catch( Exception ex )
                    {
                        OnError -= (EventHandler<LowLevelErrorEventArgs>)d;
                        ActivityMonitor.CriticalErrorCollector.Add( ex, "While raising SystemActivityMonitor.OnError event." );
                    }
                }
            }
        }

Usage Example

 public void OnOpenGroup(IActivityLogGroup group)
 {
     if (group.MaskedGroupLevel >= LogLevel.Error)
     {
         string s = DumpErrorText(group.LogTime, group.GroupText, group.MaskedGroupLevel, group.GroupTags, group.EnsureExceptionData());
         SystemActivityMonitor.HandleError(s);
     }
 }
All Usage Examples Of CK.Core.SystemActivityMonitor::HandleError