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
{
///
/// RequestLogs service Route, default is /requestlogs
///
public string AtRestPath { get; set; }
///
/// Turn On/Off Session Tracking
///
public bool EnableSessionTracking { get; set; }
///
/// Turn On/Off Tracking of Responses
///
public bool EnableResponseTracking { get; set; }
///
/// Turn On/Off Tracking of Exceptions
///
public bool EnableErrorTracking { get; set; }
///
/// Size of InMemoryRollingRequestLogger circular buffer
///
public int? Capacity { get; set; }
///
/// Limit access to /requestlogs service to these roles
///
public string[] RequiredRoles { get; set; }
///
/// Change the RequestLogger provider. Default is InMemoryRollingRequestLogger
///
public IRequestLogger RequestLogger { get; set; }
///
/// Don't log requests of these types. By default RequestLog's are excluded
///
public Type[] ExcludeRequestDtoTypes { get; set; }
///
/// Don't log request bodys for services with sensitive information.
/// By default Auth and Registration requests are hidden.
///
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(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);
}
}
}