예제 #1
0
        public override void OnActionExecuting(HttpActionContext actionContext)
        {
            this._logItem = new GatewayUsageLog();
            this._logItem.CreatedTimestamp = DateTime.UtcNow;

            try
            {
                var authorizationHeader = actionContext.Request.Headers.Authorization;

                this._logItem.SessionToken    = (authorizationHeader != null && authorizationHeader.Scheme == "SessionToken") ? authorizationHeader.Parameter : string.Empty;
                this._logItem.ClientIPAddress = GetClientIp(actionContext.Request);
                this._logItem.Method          = actionContext.ActionDescriptor.ActionName;
                this._logItem.ControllerName  = actionContext.ControllerContext.ControllerDescriptor.ControllerType.FullName;

                var arguments = actionContext.ActionArguments;
                if (arguments != null && arguments.Count > 0)
                {
                    var propertiesContractResolver = new PropertiesContractResolver();
                    propertiesContractResolver.ExcludeProperties.Add("CredentialModel.Password");

                    var serializerSettings = new JsonSerializerSettings();
                    serializerSettings.ContractResolver = propertiesContractResolver;

                    var args = Newtonsoft.Json.JsonConvert.SerializeObject(arguments, serializerSettings);

                    this._logItem.Arguments = Newtonsoft.Json.JsonConvert.SerializeObject(arguments).Substring(0, args.Length >= MaxContentLength ? MaxContentLength : args.Length);
                }
            }
            catch
            {
            }
        }
예제 #2
0
        public async Task <IHttpActionResult> LogGatewayUsage(GatewayUsageLogModel model)
        {
            using (var dbContext = new DataContext())
            {
                var logItem = new GatewayUsageLog();
                logItem.CreatedTimestamp       = model.CreatedTimestamp;
                logItem.SessionToken           = model.SessionToken;
                logItem.ClientIPAddress        = model.ClientIPAddress;
                logItem.Method                 = model.Method;
                logItem.ControllerName         = model.ControllerName;
                logItem.Arguments              = model.Arguments;
                logItem.ResponseCode           = model.ResponseCode;
                logItem.Exception              = model.Exception;
                logItem.ResponseType           = model.ResponseType;
                logItem.DurationInMilliSeconds = model.DurationInMilliSeconds;

                dbContext.GatewayUsageLogs.Add(logItem);
                await dbContext.SaveChangesAsync();

                return(Ok());
            }
        }