예제 #1
0
        public void LogDetailMessage(String message, LT319.Common.Models.DetailRequest detailLogRequest, NLog.LogLevel logLevel)
        {
            var eventInfo = new LogEventInfo(logLevel, logger.Name, message);

            eventInfo.Properties["TrackingGuid"]               = detailLogRequest.TrackingGuid;
            eventInfo.Properties["ST_ApplicationId"]           = detailLogRequest.ST_ApplicationId;
            eventInfo.Properties["TM_MappingCollectionTypeId"] = detailLogRequest.MappingCollectionTypeId;
            eventInfo.Properties["Activity"]       = detailLogRequest.Activity;
            eventInfo.Properties["Status"]         = detailLogRequest.DetailStatus;
            eventInfo.Properties["DetailDateTime"] = detailLogRequest.ActivityTimestamp;
            eventInfo.Properties["Details"]        = detailLogRequest.Details;
            // You can also add them like this:
            //eventInfo.Properties.Add("CustomNumber", 42);
            // Send to Log
            logger.Log(eventInfo);
        }
예제 #2
0
        /// <summary>
        /// Log all events here
        /// </summary>
        /// <param name="details"></param>
        /// <param name="activity"></param>
        /// <param name="trackingStatus"></param>
        /// <param name="context"></param>
        /// <param name="trackingGuid"></param>
        /// <param name="logType"></param>
        public static void LogTrackingEvent(string details, string activity, LT319.Common.Utilities.Constants.TrackingStatus trackingStatus, Sheev.Common.BaseModels.IBaseContextModel context, Guid?trackingGuid)
        {
            try
            {
                string status = string.Empty;

                // Get the status for the activity based on the value passed in for trackingStatus
                switch (trackingStatus)
                {
                case LT319.Common.Utilities.Constants.TrackingStatus.Active:
                    status = "Active";
                    break;

                case LT319.Common.Utilities.Constants.TrackingStatus.Complete:
                    status = "Complete";
                    break;

                case LT319.Common.Utilities.Constants.TrackingStatus.Error:
                    status = "Error";
                    break;
                }

                // Create a new Detail Request and build the request that will be added to the database
                LT319.Common.Models.DetailRequest logRequest = new LT319.Common.Models.DetailRequest()
                {
                    Details                 = details,
                    ST_ApplicationId        = context.GenericSettings == null ? 0: (int)context.GenericSettings.Value.ApplicationId,
                    Activity                = activity,
                    ActivityTimestamp       = DateTimeOffset.Now,
                    MappingCollectionTypeId = (int)Sheev.Common.Utilities.Constants.TM_MappingCollectionType.NONE,
                    TrackingGuid            = trackingGuid.Value,
                    DetailStatus            = status.ToString()
                };

                // Create a new Tracking Detail Log
                Utilities.TrackingDetailLog trackingLogRequest = new TrackingDetailLog()
                {
                    Token = context.Security.GetAuthToken(),
                    TrackingDetailLogRequest = logRequest
                };

                if (threadedTrackingLogger == null)
                {
                    threadedTrackingLogger = new ThreadedLogger_TrackingDetail();
                }

                //check if the application is logging the message don't have NLog set.
                if (context.NLogger != null)
                {
                    //Log using NLog
                    if (status == "Error")
                    {
                        context.NLogger.LogDetailMessage($"Log Detail ({status})", trackingLogRequest.TrackingDetailLogRequest, NLog.LogLevel.Error);
                    }
                    else
                    {
                        context.NLogger.LogDetailMessage($"Log Detail ({status})", trackingLogRequest.TrackingDetailLogRequest, NLog.LogLevel.Info);
                    }
                }

                //If still needed to update the header for each detail created, then make sure
                //the header is null and call the below method(I think the only thing that
                //needs to be updated in the header is the 'Status' and 'EndDate.
                //Maybe better to create an endpoint 'UpdateHeader'

                // Log the message details
                //To remove logging to old logger comment the below statement
                threadedTrackingLogger.LogMessage(trackingLogRequest, context);
            }
            catch (Exception ex)
            {
                //string errorMessage = $"Error: {ex.Message} while trying to log: {details}";
                string errorMessage = JsonConvert.SerializeObject(ex, Formatting.Indented);

                BackupLogger(errorMessage, "Logging.LogTrackingEvent()", EventLogEntryType.Error, context, trackingGuid);
            }
        }