Пример #1
0
        public void IGLogMessage(String message, Sheev.Common.Models.BackupLogRequest iGLogRequest, NLog.LogLevel logLevel)
        {
            var eventInfo = new LogEventInfo(logLevel, logger.Name, message);

            eventInfo.Properties["ST_ApplicationId"] = iGLogRequest.ApplicationId;
            eventInfo.Properties["DV_CompanyId"]     = iGLogRequest.CompanyId;
            eventInfo.Properties["EventType"]        = iGLogRequest.EventType;
            eventInfo.Properties["Location"]         = iGLogRequest.Location;
            eventInfo.Properties["Message"]          = iGLogRequest.Message;
            eventInfo.Properties["Scope"]            = iGLogRequest.Scope;
            eventInfo.Properties["ReferenceId"]      = iGLogRequest.ReferenceId;
            // Send to Log
            logger.Log(eventInfo);
        }
        protected override void AsyncLogMessage(object row, Sheev.Common.BaseModels.IBaseContextModel context)
        {
            Sheev.Common.Models.BackupLogRequest logRequest = ((Sheev.Common.Models.BackupLogRequest)row);

            try
            {
                // This is now under MongoDB control
                // MongoDB Settings
                string connectionString = context.MongoDbSettings.Value.ConnectionString;
                var    database         = context.MongoDbSettings.Value.Databases.FirstOrDefault(x => x.Name == "IG2000");
                string collectionName   = database.Collections.FirstOrDefault(x => x.Name == "IG_Log").Name;

                // Get MongoDB
                var client        = new MongoClient(connectionString);
                var db            = client.GetDatabase(database.Name);
                var logCollection = db.GetCollection <IG2000.Data.Models.IG_Log>(collectionName);

                // Word up... its the code word
                var dbLog = new IG2000.Data.Models.IG_Log();

                //Convert Request
                dbLog.ConvertToDatabaseObject(logRequest, (Guid)logRequest.CompanyId);

                //Add Timestamp
                dbLog.Timestamp = DateTimeOffset.Now.ToString("yyyy/MM/dd hh:mm:ss.fff tt zzz");

                //Insert
                logCollection.InsertOne(dbLog);
            }
            catch (Exception ex)
            {
                // Backup Logger
                var restClient            = new RestSharp.RestClient(context.ApiUrlSettings.Value.BackupLogger_URL);
                RestSharp.RestRequest req = new RestSharp.RestRequest("/Todd/Damnit", RestSharp.Method.POST);
                var bodyJSON = JsonConvert.SerializeObject(logRequest);
                req.AddParameter("application/json", bodyJSON, ParameterType.RequestBody);
                var resp = (RestSharp.RestResponse)restClient.Execute(req);
            }
        }
Пример #3
0
        /// <summary>
        /// Log all events here
        /// </summary>
        /// <param name="message"></param>
        /// <param name="location"></param>
        /// <param name="eventType"></param>
        /// <param name="trackingGuid"></param>
        public static void LogEvent(string message, string location, EventLogEntryType eventType, Sheev.Common.BaseModels.IBaseContextModel context, Guid?trackingGuid = null)
        {
            try
            {
                // Create the Backup Log Request
                Sheev.Common.Models.BackupLogRequest logRequest = new Sheev.Common.Models.BackupLogRequest()
                {
                    ApplicationId                                 = (int)context.GenericSettings.Value.ApplicationId,
                    CompanyId                                     = context.Security == null?Guid.Parse("BEA5A8E3-345A-4277-8669-2263E1939E3C") : context.Security.GetCompanyId(),
                                                      EventType   = eventType.ToString(),
                                                      Location    = location,
                                                      Message     = message,
                                                      ReferenceId = trackingGuid.HasValue ? trackingGuid.Value.ToString() : null
                };

                // Create a new Threaded Logger Tech Detail is one does not already exist
                if (threadedTechLogger == null)
                {
                    threadedTechLogger = new ThreadedLogger_TechDetail();
                }

                //Nlog*******
                string logLevel = string.Empty;
                // Get the logLevel for the value passed in for eventType
                switch (eventType)
                {
                case EventLogEntryType.Error:
                    logLevel = "Error";
                    break;

                case EventLogEntryType.Warning:
                    logLevel = "Warning";
                    break;

                case EventLogEntryType.Information:
                    logLevel = "Information";
                    break;
                }

                if (context.NLogger != null)
                {
                    if (logLevel == "Error")
                    {
                        context.NLogger.IGLogMessage($"IG_Log", logRequest, NLog.LogLevel.Error);
                    }
                    else if (logLevel == "Warning")
                    {
                        context.NLogger.IGLogMessage($"IG_Log", logRequest, NLog.LogLevel.Warn);
                    }
                    else
                    {
                        context.NLogger.IGLogMessage($"IG_Log", logRequest, NLog.LogLevel.Info);
                    }
                }
                //*********

                // Log the error message
                threadedTechLogger.LogMessage(logRequest, context);
            }
            catch (Exception ex)
            {
                string errorMessage = $"Error: {ex.Message} while trying to log: {message}";

                BackupLogger(errorMessage, location, eventType, context, trackingGuid);
            }
        }