Ejemplo n.º 1
0
        private void FinalizeCapture(
            LoggerEvent evt,
            LoggerLevel level,
            Exception exception,
            object data)
        {
            StackFrame sf = null;

            if (this.NeedStackFrame)
            {
                sf = Utility.FindStackFrame(true);
            }

            evt.Exception  = ExceptionData.Create(exception);
            evt.Level      = level ?? evt.Level ?? LoggerLevel.Debug;
            evt.StackFrame = sf;
            evt.ThreadName = Thread.CurrentThread.Name ?? Thread.CurrentThread.ManagedThreadId.ToString();
            evt.FinalizeTimestamp(DateTime.UtcNow);
            evt.Source = this.Name;

            if (evt.SourceLogger == null)
            {
                evt.SourceLogger = this;
            }

            Capturing(data, evt);
            Capture(evt);
        }
Ejemplo n.º 2
0
        internal static ExceptionData Create(Exception ex)
        {
            if (ex == null)
            {
                return(null);
            }

            int hResult = 0;

            try {
                PropertyInfo pi = typeof(Exception).GetTypeInfo().GetProperty(
                    "HResult", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
                hResult = (pi == null) ? 0 : (int)pi.GetValue(ex, null);
            } catch (AmbiguousMatchException) {
            } catch (MethodAccessException) {
            }

            ExceptionData result = new ExceptionData {
                HelpLink       = ex.HelpLink,
                HResult        = hResult,
                InnerException = Create(ex.InnerException),
                Message        = ex.Message,
                Source         = ex.Source,
                StackTrace     = ex.StackTrace,
                ExceptionType  = TypeReference.FromType(ex.GetType()),
            };

            foreach (DictionaryEntry de in ex.Data)
            {
                string s = de.Key as string;
                if (s == null)
                {
                    continue;
                }

                result.Data.Add(s, de.Value);
            }
            return(result);
        }