SuppressFirstChanceExceptionLogMessages() public static method

Sets a flag that will prevent First Chance Exception log messages from being raised on this thread. Remember to dispose of the callback to remove this suppression.
public static SuppressFirstChanceExceptionLogMessages ( ) : IDisposable
return IDisposable
Example #1
0
        /// <summary>
        /// Creates a <see cref="LogStackFrame"/> from a <see cref="StackFrame"/>
        /// </summary>
        /// <param name="frame"></param>
        public LogStackFrame(StackFrame frame)
        {
            if (frame == null)
            {
                ClassName    = string.Empty;
                MethodName   = string.Empty;
                FileName     = string.Empty;
                NativeOffset = 0;
                LineNumber   = 0;
                ColumnNumber = 0;
                return;
            }

            ClassName  = frame.GetMethod().GetFriendlyClassName();
            MethodName = frame.GetMethod().GetFriendlyMethodName();
            using (Logger.SuppressFirstChanceExceptionLogMessages())
            {
                try
                {
                    FileName = frame.GetFileName() ?? string.Empty;
                }
                catch (SecurityException)
                {
                    FileName = string.Empty;
                }
            }
            NativeOffset = frame.GetNativeOffset();
            LineNumber   = frame.GetFileLineNumber();
            ColumnNumber = frame.GetFileColumnNumber();
        }
Example #2
0
 /// <summary>
 /// Raises the <see cref="NewLogMessage"/> event.
 /// </summary>
 /// <param name="logMessage">the message to raise.</param>
 private void OnLog(LogMessage logMessage)
 {
     if (logMessage == null)
     {
         return;
     }
     try
     {
         using (Logger.SuppressFirstChanceExceptionLogMessages())
         {
             NewLogMessage?.Invoke(logMessage);
         }
     }
     catch (Exception)
     {
         //Swallow this exception
         //This is because if a subscriber throws an exception, creating a new log
         //might cause an infinite loop.
     }
 }