public bool SaveLog(ITrafficLog trafficLog) { try { if (trafficLog == null) { throw new ArgumentNullException(nameof(trafficLog)); } WebEventDocumentWriter.WriteDocumentAsync(trafficLog); if (trafficLog.Request.Body != null) { WebEventBodyDocumentWriter.Write( trafficLog.Request.FullUrl, trafficLog.Request.Body, trafficLog.ApplicationId, trafficLog.Client.Id, trafficLog.TraceId, IndexEventSplunkType.RequestBody); } if (trafficLog.Response.Body != null) { WebEventBodyDocumentWriter.Write( trafficLog.Request.FullUrl, trafficLog.Response.Body, trafficLog.ApplicationId, trafficLog.Client.Id, trafficLog.TraceId, IndexEventSplunkType.ResponseBody); } return(true); } catch (Exception ex) { Logger.LogError(ex, ex.Message); } return(false); }
public bool SaveLog(ITrafficLog trafficLog) { if (trafficLog == null) { throw new ArgumentNullException(nameof(trafficLog)); } string trafficLogAsString = PrepareLog(trafficLog); if (string.IsNullOrEmpty(trafficLogAsString)) { throw new NullReferenceException(nameof(trafficLogAsString)); } var pathToUserLogFolder = Path.Combine(Configuration.Folder, DateTime.UtcNow.ToString("yyyy-MM-dd"), trafficLog.Client.Id); HandleLogFolder(pathToUserLogFolder); var trafficLogFileName = GetFileName(trafficLog); if (string.IsNullOrEmpty(trafficLogFileName)) { throw new NullReferenceException(nameof(trafficLogFileName)); } var pathToTrafficLogFile = Path.Combine(pathToUserLogFolder, trafficLogFileName); WriteLogToFile(pathToTrafficLogFile, PrepareLog(trafficLog), Encoding.UTF8); return(true); }
private string TransformLogToString(ITrafficLog log) { return(JsonConvert.SerializeObject(log, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore })); }
public WebEventDocument Create(ITrafficLog trafficLog) { if (trafficLog == null) { throw new ArgumentNullException(nameof(trafficLog)); } var webEventDocument = new WebEventDocument { Source = trafficLog.ApplicationId, TraceId = trafficLog.TraceId, CustomParams = trafficLog.CustomParams.ToDocuments() }; webEventDocument.Client = CreateClientDocument(trafficLog.Client) ?? throw new NullReferenceException(nameof(webEventDocument.Client)); webEventDocument.Dates = CreateDatesDocument(trafficLog.Dates) ?? throw new NullReferenceException(nameof(webEventDocument.Dates)); webEventDocument.Request = CreateRequestDocument(trafficLog.Request) ?? throw new NullReferenceException(nameof(webEventDocument.Request)); webEventDocument.Response = CreateResponseDocument(trafficLog.Response) ?? throw new NullReferenceException(nameof(webEventDocument.Response)); webEventDocument.Server = CreateServerDocument(trafficLog.Server) ?? throw new NullReferenceException(nameof(webEventDocument.Server)); return(webEventDocument); }
internal static ITrafficLogFactory CreateMockObject(ITrafficLog trafficLog, bool ignoreRequest = false, bool ignoreResponse = false) { var mockObject = new Mock <ITrafficLogFactory>(); mockObject.Setup(x => x.Create(It.IsAny <ITrafficLogParams>(), ignoreRequest, ignoreResponse)) .Returns(trafficLog).Verifiable(); return(mockObject.Object); }
protected internal virtual string GetFileName(ITrafficLog trafficLog) { if (trafficLog == null) { throw new ArgumentNullException(nameof(trafficLog)); } var formatedDateTime = trafficLog.Dates.StartUtc.ToString(Configuration.DateTimeFormat); return($"{formatedDateTime}{trafficLog.Request.Path.Replace("/", "-")}.json"); }
protected internal virtual string PrepareLog(ITrafficLog trafficLog) { if (trafficLog == null) { throw new ArgumentNullException(nameof(trafficLog)); } if (Configuration.IgnoreClientAddressIp) { trafficLog.Client.IpAddress = null; } return(JsonConvert.SerializeObject(trafficLog, JsonSerializerSettings)); }
public void WriteDocumentAsync(ITrafficLog trafficLog) { if (trafficLog == null) { throw new ArgumentNullException(nameof(trafficLog)); } var webEventDocument = WebEventDocumentFactory.Create(trafficLog); if (webEventDocument == null) { throw new NullReferenceException(nameof(webEventDocument)); } BackgroundWebEventsQueue.Queue(IndexEventSplunkContractFactory.Create( webEventDocument, trafficLog.ApplicationId, IndexEventSplunkType.WebEvent)); }
public bool SaveLog(ITrafficLog trafficLog) { return(true); }