<commit_before>﻿using System.Threading.Tasks;
using Foundation.Core.Contracts;
using Microsoft.Owin;

namespace Foundation.Api.Middlewares
{
    public class LogRequestInformationMiddleware : OwinMiddleware
    {
        public LogRequestInformationMiddleware(OwinMiddleware next)
            : base(next)
        {
        }

        public override async Task Invoke(IOwinContext context)
        {
            IDependencyResolver dependencyResolver = context.GetDependencyResolver();

            ILogger logger = dependencyResolver.Resolve<ILogger>();

            IRequestInformationProvider requestInformationProvider =
                dependencyResolver.Resolve<IRequestInformationProvider>();

            logger.AddLogData(nameof(IRequestInformationProvider.HttpMethod), requestInformationProvider.HttpMethod);
            logger.AddLogData(nameof(IRequestInformationProvider.RequestUri), requestInformationProvider.RequestUri);

            if (requestInformationProvider.ClientAppVersion != null)
                logger.AddLogData(nameof(IRequestInformationProvider.ClientAppVersion), requestInformationProvider.ClientAppVersion);

            if (requestInformationProvider.SystemLanguage != null)
                logger.AddLogData(nameof(IRequestInformationProvider.SystemLanguage), requestInformationProvider.SystemLanguage);

            if (requestInformationProvider.ClientCulture != null)
                logger.AddLogData(nameof(IRequestInformationProvider.ClientCulture), requestInformationProvider.ClientCulture);

            if (requestInformationProvider.ClientType != null)
                logger.AddLogData(nameof(IRequestInformationProvider.ClientType), requestInformationProvider.ClientType);

            if (requestInformationProvider.ClientDateTime != null)
                logger.AddLogData(nameof(IRequestInformationProvider.ClientDateTime), requestInformationProvider.ClientDateTime);

            if (requestInformationProvider.ClientDebugMode != null)
                logger.AddLogData(nameof(IRequestInformationProvider.ClientDebugMode), requestInformationProvider.ClientDebugMode);

            if (requestInformationProvider.ClientScreenSize != null)
                logger.AddLogData(nameof(IRequestInformationProvider.ClientScreenSize), requestInformationProvider.ClientScreenSize);

            if (requestInformationProvider.ContentType != null)
                logger.AddLogData(nameof(IRequestInformationProvider.ContentType), requestInformationProvider.ContentType);

            if (requestInformationProvider.Origin != null)
                logger.AddLogData(nameof(IRequestInformationProvider.Origin), requestInformationProvider.Origin);

            if (requestInformationProvider.Referer != null)
                logger.AddLogData(nameof(IRequestInformationProvider.Referer), requestInformationProvider.Referer);

            logger.AddLogData(nameof(IRequestInformationProvider.ClientIp), requestInformationProvider.ClientIp);

            if (requestInformationProvider.ClientPlatform != null)
                logger.AddLogData(nameof(IRequestInformationProvider.ClientPlatform), requestInformationProvider.ClientPlatform);

            if (requestInformationProvider.ClientRoute != null)
                logger.AddLogData(nameof(IRequestInformationProvider.ClientRoute), requestInformationProvider.ClientRoute);

            if (requestInformationProvider.ClientSysLanguage != null)
                logger.AddLogData(nameof(IRequestInformationProvider.ClientSysLanguage), requestInformationProvider.ClientSysLanguage);

            if (requestInformationProvider.ClientTheme != null)
                logger.AddLogData(nameof(IRequestInformationProvider.ClientTheme), requestInformationProvider.ClientTheme);

            if (requestInformationProvider.UserAgent != null)
                logger.AddLogData(nameof(IRequestInformationProvider.UserAgent), requestInformationProvider.UserAgent);

            await Next.Invoke(context);
        }
    }
}<commit_msg>Log CorrelationId if provided from client<commit_after>﻿using System.Threading.Tasks;
using Foundation.Core.Contracts;
using Microsoft.Owin;

namespace Foundation.Api.Middlewares
{
    public class LogRequestInformationMiddleware : OwinMiddleware
    {
        public LogRequestInformationMiddleware(OwinMiddleware next)
            : base(next)
        {
        }

        public override async Task Invoke(IOwinContext context)
        {
            IDependencyResolver dependencyResolver = context.GetDependencyResolver();

            ILogger logger = dependencyResolver.Resolve<ILogger>();

            IRequestInformationProvider requestInformationProvider =
                dependencyResolver.Resolve<IRequestInformationProvider>();

            logger.AddLogData(nameof(IRequestInformationProvider.HttpMethod), requestInformationProvider.HttpMethod);
            logger.AddLogData(nameof(IRequestInformationProvider.RequestUri), requestInformationProvider.RequestUri);

            if (requestInformationProvider.ClientAppVersion != null)
                logger.AddLogData(nameof(IRequestInformationProvider.ClientAppVersion), requestInformationProvider.ClientAppVersion);

            if (requestInformationProvider.SystemLanguage != null)
                logger.AddLogData(nameof(IRequestInformationProvider.SystemLanguage), requestInformationProvider.SystemLanguage);

            if (requestInformationProvider.ClientCulture != null)
                logger.AddLogData(nameof(IRequestInformationProvider.ClientCulture), requestInformationProvider.ClientCulture);

            if (requestInformationProvider.ClientType != null)
                logger.AddLogData(nameof(IRequestInformationProvider.ClientType), requestInformationProvider.ClientType);

            if (requestInformationProvider.ClientDateTime != null)
                logger.AddLogData(nameof(IRequestInformationProvider.ClientDateTime), requestInformationProvider.ClientDateTime);

            if (requestInformationProvider.ClientDebugMode != null)
                logger.AddLogData(nameof(IRequestInformationProvider.ClientDebugMode), requestInformationProvider.ClientDebugMode);

            if (requestInformationProvider.ClientScreenSize != null)
                logger.AddLogData(nameof(IRequestInformationProvider.ClientScreenSize), requestInformationProvider.ClientScreenSize);

            if (requestInformationProvider.ContentType != null)
                logger.AddLogData(nameof(IRequestInformationProvider.ContentType), requestInformationProvider.ContentType);

            if (requestInformationProvider.Origin != null)
                logger.AddLogData(nameof(IRequestInformationProvider.Origin), requestInformationProvider.Origin);

            if (requestInformationProvider.Referer != null)
                logger.AddLogData(nameof(IRequestInformationProvider.Referer), requestInformationProvider.Referer);

            logger.AddLogData(nameof(IRequestInformationProvider.ClientIp), requestInformationProvider.ClientIp);

            if (requestInformationProvider.ClientPlatform != null)
                logger.AddLogData(nameof(IRequestInformationProvider.ClientPlatform), requestInformationProvider.ClientPlatform);

            if (requestInformationProvider.ClientRoute != null)
                logger.AddLogData(nameof(IRequestInformationProvider.ClientRoute), requestInformationProvider.ClientRoute);

            if (requestInformationProvider.ClientSysLanguage != null)
                logger.AddLogData(nameof(IRequestInformationProvider.ClientSysLanguage), requestInformationProvider.ClientSysLanguage);

            if (requestInformationProvider.ClientTheme != null)
                logger.AddLogData(nameof(IRequestInformationProvider.ClientTheme), requestInformationProvider.ClientTheme);

            if (requestInformationProvider.UserAgent != null)
                logger.AddLogData(nameof(IRequestInformationProvider.UserAgent), requestInformationProvider.UserAgent);

            if (requestInformationProvider.CorrelationId != null)
                logger.AddLogData(nameof(IRequestInformationProvider.CorrelationId), requestInformationProvider.CorrelationId);

            await Next.Invoke(context);
        }
    }
}
{'fraction_non_alphanumeric': 0.07197382769901854, 'fraction_numerical': 0.0, 'mean_word_length': 3.8128279883381926, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6892312', 'n_tokens_mistral': 1822, 'n_tokens_neox': 1757, 'n_words': 238}