forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRequestLogsFeature.cs
More file actions
98 lines (83 loc) · 3.42 KB
/
RequestLogsFeature.cs
File metadata and controls
98 lines (83 loc) · 3.42 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
using System;
using ServiceStack.Admin;
using ServiceStack.Configuration;
using ServiceStack.Host;
using ServiceStack.Web;
namespace ServiceStack
{
public class RequestLogsFeature : IPlugin
{
/// <summary>
/// RequestLogs service Route, default is /requestlogs
/// </summary>
public string AtRestPath { get; set; }
/// <summary>
/// Turn On/Off Session Tracking
/// </summary>
public bool EnableSessionTracking { get; set; }
/// <summary>
/// Turn On/Off Logging of Raw Request Body, default is Off
/// </summary>
public bool EnableRequestBodyTracking { get; set; }
/// <summary>
/// Turn On/Off Tracking of Responses
/// </summary>
public bool EnableResponseTracking { get; set; }
/// <summary>
/// Turn On/Off Tracking of Exceptions
/// </summary>
public bool EnableErrorTracking { get; set; }
/// <summary>
/// Size of InMemoryRollingRequestLogger circular buffer
/// </summary>
public int? Capacity { get; set; }
/// <summary>
/// Limit access to /requestlogs service to these roles
/// </summary>
public string[] RequiredRoles { get; set; }
/// <summary>
/// Change the RequestLogger provider. Default is InMemoryRollingRequestLogger
/// </summary>
public IRequestLogger RequestLogger { get; set; }
/// <summary>
/// Don't log requests of these types. By default RequestLog's are excluded
/// </summary>
public Type[] ExcludeRequestDtoTypes { get; set; }
/// <summary>
/// Don't log request bodys for services with sensitive information.
/// By default Auth and Registration requests are hidden.
/// </summary>
public Type[] HideRequestBodyForRequestDtoTypes { get; set; }
public RequestLogsFeature(int? capacity = null)
{
this.AtRestPath = "/requestlogs";
this.Capacity = capacity;
this.RequiredRoles = new [] { RoleNames.Admin };
this.EnableErrorTracking = true;
this.EnableRequestBodyTracking = false;
this.ExcludeRequestDtoTypes = new[] { typeof(RequestLogs) };
this.HideRequestBodyForRequestDtoTypes = new[] {
typeof(Authenticate), typeof(Register)
};
}
public void Register(IAppHost appHost)
{
appHost.RegisterService<RequestLogsService>(AtRestPath);
var requestLogger = RequestLogger ?? new InMemoryRollingRequestLogger(Capacity);
requestLogger.EnableSessionTracking = EnableSessionTracking;
requestLogger.EnableResponseTracking = EnableResponseTracking;
requestLogger.EnableRequestBodyTracking = EnableRequestBodyTracking;
requestLogger.EnableErrorTracking = EnableErrorTracking;
requestLogger.RequiredRoles = RequiredRoles;
requestLogger.ExcludeRequestDtoTypes = ExcludeRequestDtoTypes;
requestLogger.HideRequestBodyForRequestDtoTypes = HideRequestBodyForRequestDtoTypes;
appHost.Register(requestLogger);
if (EnableRequestBodyTracking)
{
appHost.PreRequestFilters.Insert(0, (httpReq, httpRes) => {
httpReq.UseBufferedStream = EnableRequestBodyTracking;
});
}
}
}
}