/// <summary>
        /// This is the base constructor.
        /// </summary>
        /// <param name="context">This is the API context.</param>
        /// <param name="level">This enumeration determines which part of the data should be logged.</param>
        public AspNetCoreBoundaryEvent(HttpContext context, ApiBoundaryLoggingFilterLevel level, Exception logEx)
        {
            Level     = level;
            mContext  = context;
            Direction = ChannelDirection.Incoming;
            Type      = BoundaryEventType.Interface;
            Id        = Guid.NewGuid();
            Ex        = logEx;

            //if ((level & ApiBoundaryLoggingFilterLevel.Exception) > 0)
            //    Ex = context.Exception;

            //var exceptionFeature = context.Features.Get<IExceptionHandlerPathFeature>();

            if ((level & ApiBoundaryLoggingFilterLevel.Request) > 0)
            {
                Request = new ApiHttpRequestWrapper(context);
            }

            if ((level & ApiBoundaryLoggingFilterLevel.Response) > 0)
            {
                Response = new ApiHttpResponseWrapper(context);
            }

            //if ((level & ApiBoundaryLoggingFilterLevel.RequestContent) > 0)
            //    RequestBody = new ApiMimeContent(context.Request.);

            //if ((level & ApiBoundaryLoggingFilterLevel.ResponseContent) > 0)
            //    ResponseBody = new ApiMimeContent(context.Response);
        }
示例#2
0
        /// <summary>
        /// This is the base constructor.
        /// </summary>
        /// <param name="context">This is the API context.</param>
        /// <param name="level">This enumeration determines which part of the data should be logged.</param>
        public ApiBoundaryEvent(HttpActionExecutedContext context, ApiBoundaryLoggingFilterLevel level)
        {
            Level     = level;
            mContext  = context;
            Direction = ChannelDirection.Incoming;
            Type      = BoundaryEventType.Interface;
            Id        = Guid.NewGuid();

            if ((level & ApiBoundaryLoggingFilterLevel.Exception) > 0)
            {
                Ex = context.Exception;
            }

            if ((level & ApiBoundaryLoggingFilterLevel.Request) > 0)
            {
                Request = new ApiHttpRequestWrapper(context);
            }

            if ((level & ApiBoundaryLoggingFilterLevel.Response) > 0)
            {
                Response = new ApiHttpResponseWrapper(context);
            }

            if ((level & ApiBoundaryLoggingFilterLevel.RequestContent) > 0)
            {
                RequestBody = new ApiMimeContent(context.Request.Content);
            }

            if ((level & ApiBoundaryLoggingFilterLevel.ResponseContent) > 0)
            {
                ResponseBody = new ApiMimeContent(context.Response.Content);
            }
        }
示例#3
0
        /// <summary>
        /// This pipeline method is used to add boundary logging to the WebApi.
        /// This means that all incoming requests and outgoing response can be logged to the boundary logger.
        /// </summary>
        /// <typeparam name="P">The IPipelineWebApi type.</typeparam>
        /// <param name="webpipe">The pipe.</param>
        /// <param name="level">The logging level.</param>
        /// <param name="correlationIdKey">The correlation key reftype name.</param>
        /// <param name="addToClaimsPrincipal">Specifies whether the correlation id should be added to the claims principal. The default is yes.</param>
        /// <returns></returns>
        public static P ApiAddBoundaryLoggerFilter <P>(this P webpipe
                                                       , ApiBoundaryLoggingFilterLevel level = ApiBoundaryLoggingFilterLevel.All
                                                       , string correlationIdKey             = "X-CorrelationId"
                                                       , bool addToClaimsPrincipal           = true)
            where P : IPipelineWebApi
        {
            var ms = webpipe.ToMicroservice();

            var filter = new WebApiBoundaryLoggingFilter(level, correlationIdKey, addToClaimsPrincipal);

            webpipe.HttpConfig.Filters.Add(filter);

            return(webpipe);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="app">The application builder.</param>
        /// <param name="level">The specified logging level. The default value is to log all the data.</param>
        /// <param name="correlationIdKey">The correlation Id header. The default is X-CorrelationId</param>
        /// <param name="addToClaimsPrincipal">Specifies whether to use this id to the claims principal.</param>
        /// <param name="filter">A function that can be used to filter out specific requests from logging.</param>
        /// <returns>The application builder.</returns>
        public static IApplicationBuilder UseXigadeeHttpBoundaryLogging(this IApplicationBuilder app
                                                                        , ApiBoundaryLoggingFilterLevel level = ApiBoundaryLoggingFilterLevel.All
                                                                        , string correlationIdKey             = "X-CorrelationId"
                                                                        , bool addToClaimsPrincipal           = true
                                                                        , Func <HttpContext, bool> filter     = null)
        {
            app.UseMiddleware <XigadeeHttpBoundaryLogger>(
                Options.Create(new XigadeeHttpBoundaryLoggerOptions
            {
                Level = level
                , CorrelationIdKey     = correlationIdKey
                , AddToClaimsPrincipal = addToClaimsPrincipal
                , Microservice         = app.GetXigadee()
                , Filter = filter
            })
                );

            return(app);
        }
 /// <summary>
 /// This filter can be used to log filtered incoming and outgoing Api messages and payloads to the Xigadee DataCollection infrastructure.
 /// </summary>
 /// <param name="ms">The Microservice.</param>
 /// <param name="correlationIdKeyName">The keyname for the correlation id. By default this is X-CorrelationId</param>
 /// <param name="level">The logging level</param>
 /// <param name="addToClaimsPrincipal">Specifies whether the correlation Id should be added to the claims principal</param>
 public WebApiBoundaryLoggingFilter(ApiBoundaryLoggingFilterLevel level = ApiBoundaryLoggingFilterLevel.All
                                    , string correlationIdKeyName       = "X-CorrelationId"
                                    , bool addToClaimsPrincipal         = true) : base(correlationIdKeyName, addToClaimsPrincipal)
 {
     mLevel = level;
 }