コード例 #1
0
 public static ErrorListSubmitRequest CreateErrorListSubmitRequest(string winServiceSource = "", string detail = "") {
     var errors = new List<ErrorDto>();
     var error = new ErrorDto();
     error.ErrorId = Guid.NewGuid().ToString();
     error.Source = string.IsNullOrEmpty(winServiceSource) ? "SomeCode" : winServiceSource;
     error.SourceId = "SomeCode";
     error.Type = "ExtrangeException";
     error.Detail = string.IsNullOrEmpty(detail) ? "Error Detail" : detail;
     error.Form = new Dictionary<string, string> { { "exampleFormKey", "exampleFormData" } };
     error.Host = "TheHost";
     error.InfoUrl = "";
     error.Message = "Everything is Lost";
     error.ServerVariables = new Dictionary<string, string> { { "exampleServerKey", "exampleServerData" } };
     error.StatusCode = "404";
     error.Time = DateTime.Now;
     error.User = "******";
     error.WebHostHtmlMessage = "<b>Ugly Error Message</b>";
     error.Cookies = new Dictionary<string, object> { { "exampleCookieKey", "exampleCookieData" } };
     errors.Add(error);
     return new ErrorListSubmitRequest { Errors = errors };
 }
コード例 #2
0
        private static bool AddError(ErrorDto errorDto) {
            var errorId = errorDto.ErrorId;
            var sourceId = errorDto.SourceId;
            var infoUrl = errorDto.InfoUrl;

            var infoUrlPath = string.IsNullOrWhiteSpace(infoUrl) ? string.Empty : new Uri(infoUrl).AbsoluteUri;

            var section = ConfigurationManager.GetSection("elmahr") as RootSection;
            var hasSection = section != null;
            if (!hasSection) return false;

            var apps = GlobalHost.DependencyResolver.Resolve<IApplications>();

            var source = apps[sourceId];
            if (source == null) {
                apps.AddSource("Name", sourceId, "", new SourceSection("Name", sourceId, "", null, new Dictionary<string, string>()));
                source = apps[sourceId];
            }

            var error = errorDto.ToError();

            string errorJson = JsonConvert.SerializeObject(error);

            var payload = Error.ProcessAndAppendError(sourceId, errorId, errorJson, infoUrlPath, ErrorCatcher(infoUrlPath), true);

            if (payload != null) {
                Hub.Log(string.Format("Received error from {0}: {1}", payload.GetApplication().ApplicationName, payload.Message));
            }

            return true;
        }