-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathErrorLog.cs
60 lines (48 loc) · 1.95 KB
/
ErrorLog.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Helpers;
using System.Web.Routing;
namespace Elfar.Web.Mvc
{
sealed class ErrorLog : Elfar.ErrorLog
{
public ErrorLog(Exception exception, RouteData data, HttpContextBase context) : base(exception)
{
var httpException = exception as HttpException;
if(httpException != null)
{
Code = httpException.GetHttpCode();
Html = Regex.Replace(httpException.GetHtmlErrorMessage() ?? "", @"\s*[<>{}]\s*", m => m.Value.Trim());
}
if(data != null)
{
var route = data.Route as Route;
if (route != null)
{
RouteConstraints = new Dictionary(route.Constraints);
RouteDefaults = new Dictionary(route.Defaults);
RouteUrl = route.Url;
}
RouteData = new Dictionary(data.Values);
DataTokens = new Dictionary(data.DataTokens);
Action = data.GetRequiredString("action").ToPascal();
Controller = data.GetRequiredString("controller").ToPascal();
Area = DataTokens.ContainsKey("area") ? DataTokens["area"].ToPascal() : "";
}
if (context == null) return;
try { Host = context.Server.MachineName; }
catch(HttpException) { }
var user = context.User;
if(!(user == null || string.IsNullOrWhiteSpace(user.Identity.Name))) User = user.Identity.Name;
var request = context.Request;
Url = request.Url;
HttpMethod = request.HttpMethod;
var unvalidated = request.Unvalidated();
Cookies = request.Cookies;
Form = unvalidated.Form;
QueryString = unvalidated.QueryString;
ServerVariables = request.ServerVariables;
}
}
}