コード例 #1
0
        public virtual LoggingEventData Build(
            StackFrame loggerStackFrame,
            Severity severity,
            string message,
            Exception exception,
            PropertiesDictionary properties)
        {
            var method            = loggerStackFrame.GetMethod();
            var reflectedType     = method.ReflectedType;
            var reflectedFullName = reflectedType != null ? reflectedType.FullName : string.Empty;
            var reflectedName     = reflectedType != null ? reflectedType.Name : string.Empty;

            var userName = Thread.CurrentPrincipal.Identity.Name;

            var eventData = new LoggingEventData
            {
                Domain       = AppDomain.CurrentDomain.FriendlyName,
                Identity     = userName,
                Level        = severity.ToLog4NetLevel(),
                LocationInfo = new LocationInfo(reflectedFullName,
                                                method.Name,
                                                loggerStackFrame.GetFileName(),
                                                loggerStackFrame.GetFileLineNumber().ToString()),
                LoggerName = reflectedName,
                Message    = message ?? exception.Message,
                TimeStamp  = DateTime.Now,
                UserName   = userName,
                Properties = properties
            };

            return(eventData);
        }
コード例 #2
0
            private LoggingEvent HandlePropertiesBuildingException(Exception ex, Severity severity)
            {
                var properties = new PropertiesDictionary();

                if (_exception != null)
                {
                    properties["Original.Exception.Message"]    = _exception.Message;
                    properties["Original.Exception.StackTrace"] = _exception.StackTrace;
                }

                if (!string.IsNullOrEmpty(_message))
                {
                    properties["Original.Message"] = _message;
                }

                try
                {
                    properties["Exception"] = new LoggableException(ex);
                }
                catch
                {
                    properties["Exception.Message"]    = ex.Message;
                    properties["Exception.StackTrace"] = ex.StackTrace;
                }

                properties["MachineName"] = Environment.MachineName;
                var eventData = new LoggingEventData
                {
                    Message    = "Error building log properties",
                    Properties = properties,
                    Level      = severity.ToLog4NetLevel()
                };

                return(new LoggingEvent(eventData));
            }