Quilt4.Service.WebApiApplication.LogException C# (CSharp) Method

LogException() public static method

public static LogException ( Exception exception, LogLevel logLevel ) : void
exception System.Exception
logLevel LogLevel
return void
        public static void LogException(Exception exception, LogLevel logLevel)
        {
            if (exception == null) return;

            try
            {
                ExceptionIssueLevel? issueLevel;
                switch (logLevel)
                {
                    case LogLevel.DoNotLog:
                        return;
                    case LogLevel.Error:
                        issueLevel = ExceptionIssueLevel.Error;
                        break;
                    case LogLevel.Warning:
                        issueLevel = ExceptionIssueLevel.Warning;
                        break;
                    case LogLevel.Information:
                        issueLevel = ExceptionIssueLevel.Information;
                        break;
                    case LogLevel.SystemError:
                        issueLevel = null;
                        break;
                    default:
                        issueLevel = null;
                        break;
                }

                if (!HasOwnProjectApiKey())
                {
                    issueLevel = null;
                }

                Quilt4Net.ExceptionExtensions.AddData(exception, "ExceptionKey", Guid.NewGuid());

                if (issueLevel != null)
                {
                    var issueHandler = _container.Resolve<IIssueHandler>();
                    issueHandler.IssueRegistrationCompletedEvent += IssueHandler_IssueRegistrationCompletedEvent;
                    issueHandler.RegisterStart(exception, issueLevel.Value);
                }
                else
                {
                    var log = _container.Resolve<IServiceLog>();
                    log.LogException(exception, logLevel);
                }
            }
            catch (Exception exp)
            {
                HttpContext.Current.Response.Write("<html><body>");
                HttpContext.Current.Response.Write("Unable to log exception. Reason: " + exp.Message + "</br>");
                HttpContext.Current.Response.Write("The original exception that could not be logged: " + exception.Message + "</br>");
                HttpContext.Current.Response.Write("</body></html>");
                HttpContext.Current.Response.End();
            }
        }