-
Notifications
You must be signed in to change notification settings - Fork 106
Expand file tree
/
Copy pathHttpRequestLog.cs
More file actions
99 lines (86 loc) · 3.1 KB
/
Copy pathHttpRequestLog.cs
File metadata and controls
99 lines (86 loc) · 3.1 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// -----------------------------------------------------------------------
// <copyright file="HttpRequestLog.cs" company="SimpleBrowser">
// Copyright © 2010 - 2019, Nathan Ridley and the SimpleBrowser contributors.
// See https://github.com/SimpleBrowserDotNet/SimpleBrowser/blob/master/readme.md
// </copyright>
// -----------------------------------------------------------------------
namespace SimpleBrowser
{
using System;
using System.Collections.Specialized;
using System.Net;
using System.Xml.Linq;
public abstract class LogItem
{
protected LogItem()
{
this.ServerTime = DateTime.UtcNow;
}
public DateTime ServerTime { get; set; }
}
public class HttpRequestLog : LogItem
{
public string Text { get; set; }
public string ParsedHtml { get; set; }
public string Method { get; set; }
public NameValueCollection PostData { get; set; }
public string PostBody { get; set; }
public NameValueCollection QueryStringData { get; set; }
public WebHeaderCollection RequestHeaders { get; set; }
public WebHeaderCollection ResponseHeaders { get; set; }
public int ResponseCode { get; set; }
public Uri Url { get; set; }
public Uri Address { get; set; }
public string Host { get; set; }
public XDocument ToXml()
{
XDocument doc = new XDocument(
new XElement("HttpRequestLog",
new XAttribute("Date", DateTime.UtcNow.ToString("u")),
new XElement("Url", this.Url),
new XElement("Method", this.Method),
new XElement("ResponseCode", this.ResponseCode),
new XElement("ResponseText", new XCData(this.Text))
)
);
if (this.PostData != null)
{
doc.Root.Add(this.PostData.ToXElement("PostData"));
}
if (this.RequestHeaders != null)
{
doc.Root.Add(this.RequestHeaders.ToXElement("RequestHeaders"));
}
if (this.ResponseHeaders != null)
{
doc.Root.Add(this.ResponseHeaders.ToXElement("ResponseHeaders"));
}
return doc;
}
public override string ToString()
{
return string.Concat("{", this.Method, " to ", this.Url.ToString().ShortenTo(50, true), "}");
}
}
public class LogMessage : LogItem
{
public LogMessage(string message, LogMessageType type = LogMessageType.User)
{
this.Message = message;
this.Type = type;
}
public string Message { get; set; }
public LogMessageType Type { get; set; }
public override string ToString()
{
return string.Concat("{", this.Message.ShortenTo(80, true), "}");
}
}
public enum LogMessageType
{
User,
Internal,
Error,
StackTrace
}
}