Yodiwo.DebugEx.TraceError C# (CSharp) Méthode

TraceError() private méthode

private TraceError ( Exception ex, string message, bool reportIt = true, [ filePath = "", [ lineNumber, [ method = "" ) : void
ex System.Exception
message string
reportIt bool
filePath [
lineNumber [
method [
Résultat void
        public static void TraceError(Exception ex, string message, bool reportIt = true, [CallerFilePath] string filePath = "", [CallerLineNumber] int lineNumber = 0, [CallerMemberNameAttribute] string method = "")
        {
            if (LogLevel > eTraceType.Error)
                return;
#if DEBUG
            try { var p = Path.GetFileName(filePath); } catch { Debug.Assert(false, "Invalid Log message"); };
#endif
            var fileName = Path.GetFileName(filePath);
            var failure = new YIncident() { FilePath = filePath, FileName = fileName, LineNumber = lineNumber, Method = method };
            failure.StackTrace = new StackTrace(ex, true);

#if NETFX
            try { Trace.WriteLine("Exception caught! Stack trace: " + ex.StackTrace + "" + Environment.NewLine); } catch { }
#elif UNIVERSAL
            try { Debug.WriteLine("Exception caught! Stack trace: " + ex.StackTrace + "" + Environment.NewLine); } catch { }
#endif
            try { TraceLine?.Invoke(eTraceType.Error, "Exception caught! Stack trace: " + ex.StackTrace + "" + Environment.NewLine); } catch { }

            while (ex != null)
            {
                failure.Messages.Add(ex.Message);
#if NETFX
                try { Trace.WriteLine(String.Format("{0} ERROR {1} [{2}:{3}] :: {4}", DateTime.Now, Path.GetFileName(filePath), method, lineNumber, message + " (" + ex.Message + ")")); } catch { }
#elif UNIVERSAL
                try { Debug.WriteLine(String.Format("{0} ERROR {1} [{2}:{3}] :: {4}", DateTime.Now, Path.GetFileName(filePath), method, lineNumber, message + " (" + ex.Message + ")")); } catch { }
#endif
                try { TraceLine?.Invoke(eTraceType.Error, String.Format("{0} ERROR {1} [{2}:{3}] :: {4}", DateTime.Now, Path.GetFileName(filePath), method, lineNumber, message + " (" + ex.Message + ")")); } catch { }
                ex = ex.InnerException;
            }

            if (reportIt)
                ThrowYIncident?.Invoke(failure);
        }

Same methods

DebugEx::TraceError ( string message, [ filePath = "", [ lineNumber, [ method = "" ) : void

Usage Example

Exemple #1
0
        //------------------------------------------------------------------------------------------------------------------------
        #endregion


        #region Constructors
        //------------------------------------------------------------------------------------------------------------------------
        static TypeCache()
        {
#if NETFX
            //add entry assembly
            var EntryAssembly = Assembly.GetEntryAssembly();
            if (EntryAssembly != null)
            {
                EntryAssemblies.Add(EntryAssembly);
            }

            //Add as many assemblies as we can
            //add from stack
            try
            {
                var frameAssemblies = new System.Diagnostics.StackTrace().GetFrames().Select(t => t.GetMethod().Module.Assembly).ToHashSet();
                foreach (var entry in frameAssemblies)
                {
                    EntryAssemblies.Add(entry);
                }
            }
            catch (Exception ex) { DebugEx.TraceError(ex, "Unhandled exception during Stack Frame assembly examination"); }

            //add from domain
            try
            {
                EntryAssemblies.AddFromSource(AppDomain.CurrentDomain.GetAssemblies());
            }
            catch (Exception ex) { DebugEx.TraceError(ex, "Unhandled exception during AppDomain assembly examination"); }
#elif UNIVERSAL
            EntryAssemblies.Add(Windows.UI.Xaml.Application.Current.GetType().GetTypeInfo().Assembly);
#endif
        }
All Usage Examples Of Yodiwo.DebugEx::TraceError