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
85 lines (72 loc) · 3.07 KB
/
RequestLogsFeature.cs
File metadata and controls
85 lines (72 loc) · 3.07 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
using System;
using System.Collections.Generic;
using ServiceStack.ServiceHost;
using ServiceStack.ServiceInterface.Auth;
using ServiceStack.ServiceInterface.Providers;
using ServiceStack.WebHost.Endpoints;
namespace ServiceStack.ServiceInterface.Admin
{
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 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.ExcludeRequestDtoTypes = new[] { typeof(RequestLogs) };
this.HideRequestBodyForRequestDtoTypes = new[] {
typeof(Auth.Auth), typeof(Registration)
};
}
public void Register(IAppHost appHost)
{
appHost.RegisterService<RequestLogsService>(AtRestPath);
var requestLogger = RequestLogger ?? new InMemoryRollingRequestLogger(Capacity);
requestLogger.EnableSessionTracking = EnableSessionTracking;
requestLogger.EnableResponseTracking = EnableResponseTracking;
requestLogger.EnableErrorTracking = EnableErrorTracking;
requestLogger.RequiredRoles = RequiredRoles;
requestLogger.ExcludeRequestDtoTypes = ExcludeRequestDtoTypes;
requestLogger.HideRequestBodyForRequestDtoTypes = HideRequestBodyForRequestDtoTypes;
appHost.Register(requestLogger);
}
}
}