public void OnFlush(FlushLogArgs args, ILogger logger) { FlushProperties flushProperties = GetAndValidateFlushProperties(args); if (flushProperties == null) { return; } InternalHelpers.Log("KissLogApiListener: OnFlush begin", LogLevel.Trace); ObfuscateService?.Obfuscate(args); TruncateService?.Truncate(args); Requests.CreateRequestLogRequest request = CreateRequestLogRequestFactory.Create(args); request.OrganizationId = flushProperties.Application.OrganizationId; request.ApplicationId = flushProperties.Application.ApplicationId; request.Keywords = Configuration.Configuration.Options.ApplyAddRequestKeywordstHeader(args); // we need to copy files, because we start a new Thread, and the existing files will be deleted before accessing them IList <LoggerFile> copy = CopyFiles(args.Files?.ToList()); IFlusher flusher = CreateFlusher(flushProperties); if (UseAsync == true) { flusher.FlushAsync(request, copy).ConfigureAwait(false); } else { flusher.Flush(request, copy); } InternalHelpers.Log("KissLogApiListener: OnFlush complete", LogLevel.Trace); }
private FlushProperties GetAndValidateFlushProperties(FlushLogArgs args) { FlushProperties result = null; if (UpdateFlushProperties != null) { result = UpdateFlushProperties(args); } if (result == null) { result = new FlushProperties { Application = _application, ApiUrl = ApiUrl, ApiVersion = ApiVersion }; } string organizationId = result.Application?.OrganizationId; string applicationId = result.Application?.ApplicationId; string apiUrl = result.ApiUrl; if (string.IsNullOrEmpty(organizationId)) { InternalHelpers.Log("KissLogApiListener: Application.OrganizationId is null", LogLevel.Error); return(null); } if (string.IsNullOrEmpty(applicationId)) { InternalHelpers.Log("KissLogApiListener: Application.applicationId is null", LogLevel.Error); return(null); } if (string.IsNullOrEmpty(apiUrl)) { InternalHelpers.Log("KissLogApiListener: ApiUrl is null", LogLevel.Error); return(null); } if (!Uri.TryCreate(apiUrl, UriKind.Absolute, out _)) { InternalHelpers.Log($"KissLogApiListener: ApiUrl \"{apiUrl}\" is not a valid Uri", LogLevel.Error); return(null); } return(result); }
private IFlusher CreateFlusher(FlushProperties flushProperties) { IFlusher flusher = null; string apiUrl = flushProperties.ApiUrl; switch (flushProperties.ApiVersion) { case ApiVersion.v1: flusher = new FlusherRestV1(apiUrl); break; default: flusher = new FlusherRestV2(apiUrl); break; } return(flusher); }