Beispiel #1
0
        public void Log(Exception exception, ErrorSeverity severity, string additionalContext)
        {
            if (exception != null && exception is ErrorLogException)
            {
                return;
            }

            var message     = String.Empty;
            var stackTrace  = String.Empty;
            var errorString = new StringBuilder();

            if (additionalContext != null)
            {
                errorString.Append("Additional context:\r\n");
                errorString.Append(additionalContext);
                errorString.Append("\r\n\r\n");
            }

            if (exception != null)
            {
                message = exception.GetType().Name + ": " + exception.Message;
                if (exception.InnerException != null)
                {
                    message += "\r\n\r\nInner exception: " + exception.InnerException.Message;
                }

                stackTrace = exception.StackTrace ?? String.Empty;
                foreach (DictionaryEntry item in exception.Data)
                {
                    errorString.Append(item.Key);
                    errorString.Append(": ");
                    errorString.Append(item.Value);
                    errorString.Append("\r\n");
                }
            }

            errorString.Append("\r\n");

            try
            {
                _errorLogRepository.Create(DateTime.UtcNow, message, stackTrace, errorString.ToString(), severity);
            }
            catch
            {
                throw new ErrorLogException(String.Format("Can't log error: {0}\r\n\r\n{1}\r\n\r\n{2}", message, stackTrace, errorString));
            }
        }
Beispiel #2
0
        public void Log(Exception exception, ErrorSeverity severity, string additionalContext)
        {
            if (exception != null && exception is ErrorLogException)
            {
                return;
            }
            var message    = string.Empty;
            var stackTrace = string.Empty;
            var s          = new StringBuilder();

            if (additionalContext != null)
            {
                s.Append("Additional context:\r\n");
                s.Append(additionalContext);
                s.Append("\r\n\r\n");
            }
            if (exception != null)
            {
                message = exception.GetType().Name + ": " + exception.Message;
                if (exception.InnerException != null)
                {
                    message += "\r\n\r\nInner exception: " + exception.InnerException.Message;
                }
                stackTrace = exception.StackTrace ?? string.Empty;
                foreach (DictionaryEntry item in exception.Data)
                {
                    s.Append(item.Key);
                    s.Append(": ");
                    s.Append(item.Value);
                    s.Append("\r\n");
                }
            }
            s.Append("\r\n");
            try
            {
                // TODO: Eventually make this async, but its web of call stacks are huge
                _errorLogRepository.Create(DateTime.UtcNow, message, stackTrace, s.ToString(), severity);
            }
            catch
            {
                throw new ErrorLogException($"Can't log error: {message}\r\n\r\n{stackTrace}\r\n\r\n{s}");
            }
        }
Beispiel #3
0
        public void Log(Exception exception, ErrorSeverity severity, string additionalContext)
        {
            var message    = String.Empty;
            var stackTrace = String.Empty;
            var s          = new StringBuilder();

            if (additionalContext != null)
            {
                s.Append("Additional context:\r\n");
                s.Append(additionalContext);
                s.Append("\r\n\r\n");
            }
            if (exception != null)
            {
                message = exception.GetType().Name + ": " + exception.Message;
                if (exception.InnerException != null)
                {
                    message += "\r\n\r\nInner exception: " + exception.InnerException.Message;
                }
                stackTrace = exception.StackTrace ?? String.Empty;
                foreach (DictionaryEntry item in exception.Data)
                {
                    s.Append(item.Key);
                    s.Append(": ");
                    s.Append(item.Value);
                    s.Append("\r\n");
                }
            }
            s.Append("\r\n");
            var context = HttpContext.Current;

            if (context != null)
            {
                if (context.User != null && context.User.Identity.IsAuthenticated)
                {
                    var user = context.User as User;
                    if (user != null)
                    {
                        s.Append("User: "******"\r\nE-mail: ");
                        s.Append(user.Email);
                        s.Append("\r\n\r\n");
                    }
                }
                lock (context.Request.ServerVariables.AllKeys.SyncRoot)
                {
                    foreach (var key in context.Request.ServerVariables.AllKeys)
                    {
                        if (context.Request.ServerVariables[key] != String.Empty && key != "ALL_HTTP")
                        {
                            s.Append(key);
                            s.Append(": ");
                            s.Append(context.Request.ServerVariables[key]);
                            s.Append("\r\n");
                        }
                    }
                }
            }
            try
            {
                _errorLogRepository.Create(DateTime.UtcNow, message, stackTrace, s.ToString(), severity);
            }
            catch
            {
                throw new ErrorLogException(String.Format("Can't log error: {0}\r\n\r\n{1}\r\n\r\n{2}", message, stackTrace, s));
            }
        }
Beispiel #4
0
 public void Create(ErrorLog error)
 {
     errorLogRepository.Create(error);
 }