66
77namespace ServiceStack . ServiceInterface . Admin
88{
9- public class RequestLogs
10- {
11- public int ? BeforeSecs { get ; set ; }
12- public int ? AfterSecs { get ; set ; }
13- public string IpAddress { get ; set ; }
14- public string ForwardedFor { get ; set ; }
15- public string UserAuthId { get ; set ; }
16- public string SessionId { get ; set ; }
17- public string Referer { get ; set ; }
18- public string PathInfo { get ; set ; }
19- public long [ ] Ids { get ; set ; }
20- public int ? BeforeId { get ; set ; }
21- public int ? AfterId { get ; set ; }
22- public bool ? HasResponse { get ; set ; }
23- public bool ? WithErrors { get ; set ; }
24- public int Skip { get ; set ; }
25- public int ? Take { get ; set ; }
26- public bool ? EnableSessionTracking { get ; set ; }
27- public bool ? EnableResponseTracking { get ; set ; }
28- public bool ? EnableErrorTracking { get ; set ; }
29- }
9+ public class RequestLogs
10+ {
11+ public int ? BeforeSecs { get ; set ; }
12+ public int ? AfterSecs { get ; set ; }
13+ public string IpAddress { get ; set ; }
14+ public string ForwardedFor { get ; set ; }
15+ public string UserAuthId { get ; set ; }
16+ public string SessionId { get ; set ; }
17+ public string Referer { get ; set ; }
18+ public string PathInfo { get ; set ; }
19+ public long [ ] Ids { get ; set ; }
20+ public int ? BeforeId { get ; set ; }
21+ public int ? AfterId { get ; set ; }
22+ public bool ? HasResponse { get ; set ; }
23+ public bool ? WithErrors { get ; set ; }
24+ public int Skip { get ; set ; }
25+ public int ? Take { get ; set ; }
26+ public bool ? EnableSessionTracking { get ; set ; }
27+ public bool ? EnableResponseTracking { get ; set ; }
28+ public bool ? EnableErrorTracking { get ; set ; }
29+ }
3030
31- public class RequestLogsResponse
32- {
33- public RequestLogsResponse ( )
34- {
35- this . Results = new List < RequestLogEntry > ( ) ;
36- }
31+ public class RequestLogsResponse
32+ {
33+ public RequestLogsResponse ( )
34+ {
35+ this . Results = new List < RequestLogEntry > ( ) ;
36+ }
3737
38- public List < RequestLogEntry > Results { get ; set ; }
39- public Dictionary < string , string > Usage { get ; set ; }
40- public ResponseStatus ResponseStatus { get ; set ; }
41- }
38+ public List < RequestLogEntry > Results { get ; set ; }
39+ public Dictionary < string , string > Usage { get ; set ; }
40+ public ResponseStatus ResponseStatus { get ; set ; }
41+ }
4242
43- public class RequestLogsService : ServiceBase < RequestLogs >
44- {
45- private static readonly Dictionary < string , string > Usage = new Dictionary < string , string > {
46- { "int BeforeSecs" , "Requests before elapsed time" } ,
47- { "int AfterSecs" , "Requests after elapsed time" } ,
48- { "string IpAddress" , "Requests matching Ip Address" } ,
49- { "string ForwardedFor" , "Requests matching Forwarded Ip Address" } ,
50- { "string UserAuthId" , "Requests matching UserAuthId" } ,
51- { "string SessionId" , "Requests matching SessionId" } ,
52- { "string Referer" , "Requests matching Http Referer" } ,
53- { "string PathInfo" , "Requests matching PathInfo" } ,
54- { "int BeforeId" , "Requests before RequestLog Id" } ,
55- { "int AfterId" , "Requests after RequestLog Id" } ,
56- { "bool WithErrors" , "Requests with errors" } ,
57- { "int Skip" , "Skip past N results" } ,
58- { "int Take" , "Only look at last N results" } ,
59- { "bool EnableSessionTracking" , "Turn On/Off Session Tracking" } ,
60- { "bool EnableResponseTracking" , "Turn On/Off Tracking of Responses" } ,
61- { "bool EnableErrorTracking" , "Turn On/Off Tracking of Errors" } ,
62- } ;
43+ public class RequestLogsService : ServiceBase < RequestLogs >
44+ {
45+ private static readonly Dictionary < string , string > Usage = new Dictionary < string , string > {
46+ { "int BeforeSecs" , "Requests before elapsed time" } ,
47+ { "int AfterSecs" , "Requests after elapsed time" } ,
48+ { "string IpAddress" , "Requests matching Ip Address" } ,
49+ { "string ForwardedFor" , "Requests matching Forwarded Ip Address" } ,
50+ { "string UserAuthId" , "Requests matching UserAuthId" } ,
51+ { "string SessionId" , "Requests matching SessionId" } ,
52+ { "string Referer" , "Requests matching Http Referer" } ,
53+ { "string PathInfo" , "Requests matching PathInfo" } ,
54+ { "int BeforeId" , "Requests before RequestLog Id" } ,
55+ { "int AfterId" , "Requests after RequestLog Id" } ,
56+ { "bool WithErrors" , "Requests with errors" } ,
57+ { "int Skip" , "Skip past N results" } ,
58+ { "int Take" , "Only look at last N results" } ,
59+ { "bool EnableSessionTracking" , "Turn On/Off Session Tracking" } ,
60+ { "bool EnableResponseTracking" , "Turn On/Off Tracking of Responses" } ,
61+ { "bool EnableErrorTracking" , "Turn On/Off Tracking of Errors" } ,
62+ } ;
6363
64- protected override object Run ( RequestLogs request )
65- {
66- if ( RequestLogger == null )
67- throw new Exception ( "No IRequestLogger is registered" ) ;
64+ protected override object Run ( RequestLogs request )
65+ {
66+ if ( RequestLogger == null )
67+ throw new Exception ( "No IRequestLogger is registered" ) ;
6868
69- RequiredRoleAttribute . AssertRequiredRoles ( RequestContext , RequestLogger . RequiresRole ) ;
70-
71- if ( request . EnableSessionTracking . HasValue )
72- RequestLogger . EnableSessionTracking = request . EnableSessionTracking . Value ;
69+ RequiredRoleAttribute . AssertRequiredRoles ( RequestContext , RequestLogger . RequiresRole ) ;
70+
71+ if ( request . EnableSessionTracking . HasValue )
72+ RequestLogger . EnableSessionTracking = request . EnableSessionTracking . Value ;
7373
74- var now = DateTime . UtcNow ;
75- var logs = RequestLogger . GetLatestLogs ( request . Take ) . AsQueryable ( ) ;
74+ var now = DateTime . UtcNow ;
75+ var logs = RequestLogger . GetLatestLogs ( request . Take ) . AsQueryable ( ) ;
7676
77- if ( request . BeforeSecs . HasValue )
78- logs = logs . Where ( x => ( now - x . DateTime ) <= TimeSpan . FromSeconds ( request . BeforeSecs . Value ) ) ;
79- if ( request . AfterSecs . HasValue )
80- logs = logs . Where ( x => ( now - x . DateTime ) > TimeSpan . FromSeconds ( request . AfterSecs . Value ) ) ;
81- if ( ! request . IpAddress . IsNullOrEmpty ( ) )
82- logs = logs . Where ( x => x . IpAddress == request . IpAddress ) ;
83- if ( ! request . UserAuthId . IsNullOrEmpty ( ) )
84- logs = logs . Where ( x => x . UserAuthId == request . UserAuthId ) ;
85- if ( ! request . SessionId . IsNullOrEmpty ( ) )
86- logs = logs . Where ( x => x . SessionId == request . SessionId ) ;
87- if ( ! request . Referer . IsNullOrEmpty ( ) )
88- logs = logs . Where ( x => x . Referer == request . Referer ) ;
89- if ( ! request . PathInfo . IsNullOrEmpty ( ) )
90- logs = logs . Where ( x => x . PathInfo == request . PathInfo ) ;
91- if ( ! request . Ids . IsEmpty ( ) )
92- logs = logs . Where ( x => request . Ids . Contains ( x . Id ) ) ;
93- if ( request . BeforeId . HasValue )
94- logs = logs . Where ( x => x . Id <= request . BeforeId ) ;
95- if ( request . AfterId . HasValue )
96- logs = logs . Where ( x => x . Id > request . AfterId ) ;
97- if ( request . WithErrors . HasValue )
98- logs = request . WithErrors . Value
99- ? logs . Where ( x => x . ErrorResponse != null )
100- : logs . Where ( x => x . ErrorResponse == null ) ;
77+ if ( request . BeforeSecs . HasValue )
78+ logs = logs . Where ( x => ( now - x . DateTime ) <= TimeSpan . FromSeconds ( request . BeforeSecs . Value ) ) ;
79+ if ( request . AfterSecs . HasValue )
80+ logs = logs . Where ( x => ( now - x . DateTime ) > TimeSpan . FromSeconds ( request . AfterSecs . Value ) ) ;
81+ if ( ! request . IpAddress . IsNullOrEmpty ( ) )
82+ logs = logs . Where ( x => x . IpAddress == request . IpAddress ) ;
83+ if ( ! request . UserAuthId . IsNullOrEmpty ( ) )
84+ logs = logs . Where ( x => x . UserAuthId == request . UserAuthId ) ;
85+ if ( ! request . SessionId . IsNullOrEmpty ( ) )
86+ logs = logs . Where ( x => x . SessionId == request . SessionId ) ;
87+ if ( ! request . Referer . IsNullOrEmpty ( ) )
88+ logs = logs . Where ( x => x . Referer == request . Referer ) ;
89+ if ( ! request . PathInfo . IsNullOrEmpty ( ) )
90+ logs = logs . Where ( x => x . PathInfo == request . PathInfo ) ;
91+ if ( ! request . Ids . IsEmpty ( ) )
92+ logs = logs . Where ( x => request . Ids . Contains ( x . Id ) ) ;
93+ if ( request . BeforeId . HasValue )
94+ logs = logs . Where ( x => x . Id <= request . BeforeId ) ;
95+ if ( request . AfterId . HasValue )
96+ logs = logs . Where ( x => x . Id > request . AfterId ) ;
97+ if ( request . WithErrors . HasValue )
98+ logs = request . WithErrors . Value
99+ ? logs . Where ( x => x . ErrorResponse != null )
100+ : logs . Where ( x => x . ErrorResponse == null ) ;
101101
102- var results = logs . Skip ( request . Skip ) . OrderByDescending ( x => x . Id ) . ToList ( ) ;
102+ var results = logs . Skip ( request . Skip ) . OrderByDescending ( x => x . Id ) . ToList ( ) ;
103103
104- return new RequestLogsResponse {
105- Results = results ,
106- Usage = Usage ,
107- } ;
108- }
109- }
104+ return new RequestLogsResponse {
105+ Results = results ,
106+ Usage = Usage ,
107+ } ;
108+ }
109+ }
110110}
0 commit comments