Пример #1
0
        public void OnFlush(FlushLogArgs args)
        {
            bool isValid = ValidateProperties();

            if (!isValid)
            {
                return;
            }

            InternalLogger.Log("RequestLogsApiListener: OnFlush begin", LogLevel.Trace);

            ObfuscateFlushLogArgsService obfuscateService = new ObfuscateFlushLogArgsService(ObfuscationService);

            obfuscateService.Obfuscate(args);

            CreateRequestLogRequest request = PayloadFactory.Create(args);

            request.OrganizationId = _application.OrganizationId;
            request.ApplicationId  = _application.ApplicationId;
            request.Keywords       = InternalHelpers.WrapInTryCatch(() => Options.Handlers.GenerateSearchKeywords(args));

            FlushOptions flushOptions = new FlushOptions
            {
                UseAsync    = UseAsync,
                OnException = OnException
            };

            IPublicApi kisslogApi = _kisslogApi ?? new PublicRestApi(ApiUrl, IgnoreSslCertificate);

            Flusher.FlushAsync(flushOptions, kisslogApi, args, request).ConfigureAwait(false);

            InternalLogger.Log("RequestLogsApiListener: OnFlush complete", LogLevel.Trace);
        }
Пример #2
0
        public static async Task FlushAsync(FlushOptions options, IPublicApi kisslogApi, FlushLogArgs flushArgs, CreateRequestLogRequest request)
        {
            IEnumerable <LoggedFile> files = CopyFiles(flushArgs);

            flushArgs.SetFiles(files);

            IEnumerable <File> requestFiles = files.Select(p => new File
            {
                FileName = p.FileName,
                FilePath = p.FilePath
            }).ToList();

            try
            {
                ApiResult <RequestLog> result = null;

                if (options.UseAsync)
                {
                    result = await kisslogApi.CreateRequestLogAsync(request, requestFiles).ConfigureAwait(false);
                }
                else
                {
                    result = kisslogApi.CreateRequestLog(request, requestFiles);
                }

                if (result.HasException && options.OnException != null)
                {
                    options.OnException.Invoke(new ExceptionArgs(flushArgs, result));
                }
            }
            finally
            {
                DeleteFiles(files);
            }
        }