public string ComposeOutputString(HistoryItemDO historyItem) { historyItem = historyItem ?? new HistoryItemDO() { Data = "HistoryItem object is null!" }; string itemType = historyItem.GetType().Name.Replace("DO", ""); //trim Data feild if it is too long, max length 256 symbols historyItem.Data = historyItem.Data ?? ""; var dataLen = historyItem.Data.Length > 256 ? 255 : historyItem.Data.Length; var substring = historyItem.Data.Substring(0, dataLen); substring = dataLen == 255 ? substring + "..." : substring; //in FactDO we have CreatedById property, so we need crutch to not have Fr8UserId empty if (typeof(FactDO) == historyItem.GetType() && historyItem.Fr8UserId.IsNullOrEmpty()) { historyItem.Fr8UserId = (historyItem as FactDO).CreatedByID; } var message = $"HistoryItemId = [{historyItem.Id}]; " + $"[{itemType}]: [{historyItem.PrimaryCategory}] " + $"[{historyItem.SecondaryCategory}]" + $"[{historyItem.Activity}], " + $"Data = [{substring}], " + $"Fr8User = [{historyItem.Fr8UserId}], " + $"ObjectId = [{historyItem.ObjectId}]"; return(message); }
private void GenerateLogData(HistoryItemDO currentIncident) { var logData = string.Format("{0} {1} {2}:" + " ObjectId: {3} CustomerId: {4}", currentIncident.PrimaryCategory, currentIncident.SecondaryCategory, currentIncident.Activity, currentIncident.ObjectId, currentIncident.Fr8UserId); //Logger.GetLogger().Info(logData); Logger.GetLogger().Info(logData); }
/// <summary> /// Logs historyItem information using the standard log mechanisms, replacement for LogFactInformation . /// </summary> /// <param name="historyItem">An instance of FactDO class.</param> /// <param name="eventType">Event type.</param> public void LogHistoryItem(HistoryItemDO historyItem, EventType eventType = EventType.Info) { var message = ComposeOutputString(historyItem); var logger = Logger.GetLogger(); if (eventType == EventType.Info) { logger.Info(message); } if (eventType == EventType.Warning) { logger.Warn(message); } if (eventType == EventType.Error) { logger.Error(message); } //Logger.LogMessage(message,eventType); }