Exemplo n.º 1
0
        public override void OnAuthorization(HttpActionContext actionContext)
        {
            try
            {
                base.OnAuthorization(actionContext);

                if (actionContext.RequestContext.Principal == null)
                {
                    logger.LogWarning(correlation, "OnAuthorization - Principal is null.");
                }
                else if (actionContext.RequestContext.Principal.Identity == null)
                {
                    logger.LogWarning(correlation, "OnAuthorization - Identity is null.");
                }
                else
                {
                    IIdentity identity = actionContext.ControllerContext.RequestContext.Principal.Identity;

                    if (identity.IsAuthenticated)
                    {
                        logger.LogVerbose(correlation, "OnAuthorization - User name: '{0}', auth type: '{1}'.", identity.Name,
                                          identity.AuthenticationType);
                    }
                    else
                    {
                        logger.LogWarning(correlation, "OnAuthorization - Identity is not authenticated. User name: '{0}', auth type: '{1}'.", identity.Name,
                                          identity.AuthenticationType);
                    }
                }
            }
            catch (Exception e)
            {
                logger.LogError(correlation, e, "Authorization error.");
            }
        }
Exemplo n.º 2
0
        public override void Log(ExceptionLoggerContext context)
        {
            ICorrelation correlation;

            try
            {
                correlation = correlationFactory.Invoke(context.Request);
            }
            catch
            {
                correlation = null;
            }

            string parameters = context.ExceptionContext.ActionContext == null ? null : context.ExceptionContext.ActionContext.ParametersToString();

            logger.LogError(correlation, context.Exception, "Unhandled exception from request: {0}({1})", context.Request, parameters);
        }