コード例 #1
0
        public void HandleLog(TCommand command, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)

        {
            LogCommand logCmd = command as LogCommand;

            //Only logging Debug messages here
            if (logCmd != null && !logCmd.LoggingInstance.Logger.IsEnabledFor(log4net.Core.Level.Debug))
            {
                return;
            }

            var adUserName = ((ClaimsIdentity)logCmd.User.Identity).Claims.FirstOrDefault(x => x.Type.ToUpper() == "SFADUSERNAME")?.Value;
            var corrId     = ((ClaimsIdentity)logCmd.User.Identity).Claims.FirstOrDefault(x => x.Type.ToUpper() == "SFCORRELATIONID")?.Value;

            Guid.TryParse(corrId, out Guid correlationId);
            LogicalThreadContext.Properties["CorrelationId"] = correlationId;
            LogicalThreadContext.Properties["AppUserName"]   = adUserName;
            var assy = Assembly.GetCallingAssembly().FullName;

            assy = assy.Substring(0, assy.IndexOf("Culture=", StringComparison.CurrentCulture) - 3);
            LogicalThreadContext.Properties["ApplicationName"] = assy;

            //Need to log optional params (memberName, sourceFilePath, sourceLineNumber) because the Log would always show this class which is doing the logging
            //in the database,  instead of the class that is calling the Logging handler which is what we really want to see
            AppLogger.LogDebug(logCmd.LoggingInstance, logCmd.LogMessage, ReplayId, memberName, sourceFilePath, sourceLineNumber);
        }
コード例 #2
0
        public void SetStatus(string new_status, StatusTypes StatusType = StatusTypes.SetValueStatus)
        {
            if (string.IsNullOrWhiteSpace(new_status) && string.IsNullOrWhiteSpace(protected_Status))
            {
                AppLogger.LogTrace("Попытка установить статус null на null. Проигнорировано.");
                return;
            }
            if (string.IsNullOrWhiteSpace(new_status) && StatusType != StatusTypes.SystemStatus)
            {
                StatusType = StatusTypes.DebugStatus;
            }

            switch (StatusType)
            {
            case StatusTypes.SetValueStatus:
                AppLogger.LogWarning(new_status);
                break;

            case StatusTypes.ErrorStatus:
                AppLogger.LogError(new_status);
                break;

            case StatusTypes.DebugStatus:
                AppLogger.LogDebug(new_status);
                break;

            case StatusTypes.SystemStatus:
                AppLogger.LogDebug("status set null");
                break;

            default:
                AppLogger.LogCritical("Тип статуса [" + StatusType.ToString() + "] за пределами доступных значений: " + new_status);
                break;
            }

            protected_Status = new_status;
            lock (TracertChangeStatus)
            {
                TracertChangeStatus.Add(new TracertItemModel()
                {
                    DateCreate = DateTime.Now, Information = new_status, TypeTracert = StatusType, Id = TracertChangeStatus.Count + 1
                });
                TracertChangeStatus = new ConcurrentBag <TracertItemModel>(TracertChangeStatus.OrderByDescending(x => x.DateCreate));

                if (TracertChangeStatus.Count() > MaximumSizeSchedulerStatusTraceStack + 10)
                {
                    TracertChangeStatus = new ConcurrentBag <TracertItemModel>(TracertChangeStatus.Skip(TracertChangeStatus.Count() - MaximumSizeSchedulerStatusTraceStack));
                }

                if (StartChangeStatusDateTime.AddSeconds(MaximumLifetimeSchedulerStatusTrace) < DateTime.Now)
                {
                    TracertChangeStatus = new ConcurrentBag <TracertItemModel>(TracertChangeStatus.Where(x => x.DateCreate > DateTime.Now.AddSeconds(-MaximumLifetimeSchedulerStatusTrace)));
                }
            }
        }
コード例 #3
0
        static void Main(string[] args)
        {
            System.Console.WriteLine("InternalDebugging");

            #region ConfigXML
            string xml = @"<?xml version='1.0' encoding='utf-8' ?>
                <configuration>
                    <configSections>
                        <section name='log4net' type='log4net.Config.Log4NetConfigurationSectionHandler, log4net' />
                    </configSections>
                    <log4net>
                        <appender name='ConsoleAppender' type='log4net.Appender.ConsoleAppender'>
                            <layout type='log4net.Layout.SimpleLayout' />
                        </appender>
                        <appender name='MongoDBAppender' type='Log4NetMongo.Appender.MongoDBAppender, Log4NetMongo.Appender'>
                            <connectionString value='mongodb://*****:*****@CAN-ALPHA:9010/MACH_LOG_CORE?authSource=admin' />
                        </appender>
                        <root>
                            <level value='ALL' />
                            <appender-ref ref='MongoDBAppender' />
                            <appender-ref ref='ConsoleAppender' />
                        </root>
                    </log4net>
                </configuration>";
            #endregion

            LogLog.InternalDebugging = true;
            var loggerRepository = LogManager.CreateRepository(Assembly.GetEntryAssembly(), typeof(log4net.Repository.Hierarchy.Hierarchy));
            using (MemoryStream stream = new MemoryStream(Encoding.ASCII.GetBytes(xml)))
            {
                XmlConfigurator.Configure(loggerRepository, stream);
            }

            ILog log = LogManager.GetLogger(typeof(Program));
            log.Info("Starting");

            //while (!System.Console.KeyAvailable)
            while (_count < 10)
            {
                log.Info(++_count);
                Thread.Sleep(Interval);
            }
            System.Console.WriteLine("Completed");

            //--
            System.Console.WriteLine("AppLogger Debugging");

            AppLogger logger = new AppLogger();
            logger.LogDebug("test debug message");

            System.Console.WriteLine("Completed");
        }
コード例 #4
0
        public void TestMethod_with_data_values()
        {
            AppLogger  logger = new AppLogger();
            DataStruct data   = new DataStruct()
            {
                Id       = 1,
                IsActive = true,
                Message  = "Data message"
            };

            logger.LogDebug($"Test Debug @ {DateTime.UtcNow}", data);
            Console.WriteLine("See output for exceptions. Completed successfully");
        }