Пример #1
0
        public static void HandleOnExit(Logging.ILogger appLogger)
        {
            Logging.LogMessage lm = appLogger.GetLogMessage(Logging.MesgType.Signif, "App Stopping", appLogger.GetStackFrame(0));
            lm.KeywordArray = new string[] { "Application", "OnExit" };
            appLogger.EmitLogMessage(ref lm);

            Logging.ShutdownLogging();
        }
Пример #2
0
        public static void HandleOnStartup(StartupEventArgs e, ref Logging.Logger appLogger, string logBaseName)
        {
            MosaicLib.Modular.Config.Config.AddStandardProviders(e.Args);

            int ringQueueSize = 500;
            int traceQueueSize = 1000;
            Logging.ListMesgEmitter issueListEmitter = new Logging.ListMesgEmitter() { MesgType = Logging.MesgType.Error };
            Logging.ListMesgEmitter valuesListEmitter = new Logging.ListMesgEmitter() { MesgType = Logging.MesgType.Debug };

            Logging.FileRotationLoggingConfig ringConfig = new Logging.FileRotationLoggingConfig((logBaseName ?? String.Empty) + "LogFile")
            {
                mesgQueueSize = ringQueueSize,
                nameUsesDateAndTime = true,
            }.UpdateFromModularConfig("Config.Logging.FileRing.", issueListEmitter, valuesListEmitter);

            Logging.FileRotationLoggingConfig traceRingConfig = new Logging.FileRotationLoggingConfig((logBaseName ?? String.Empty) + "TraceRing")
            {
                mesgQueueSize = traceQueueSize,
                nameUsesDateAndTime = false,     // will use 4 digit file names.  Limit of 100 files total
                includeThreadInfo = true,
            }.UpdateFromModularConfig("Config.Logging.TraceRing.", issueListEmitter, valuesListEmitter);

            Logging.ILogMessageHandler dirRingLMH = Logging.CreateQueuedTextFileRotationDirectoryLogMessageHandler(ringConfig);
            Logging.ILogMessageHandler lmh = null; //  Logging.CreateDiagnosticTraceLogMessageHandler(Logging.LogGate.Debug);
            Logging.ILogMessageHandler wpfLMH = MosaicLib.WPF.Logging.WpfLogMessageHandlerToolBase.Instance;

            if (dirRingLMH != null)
                Logging.AddLogMessageHandlerToDefaultDistributionGroup(dirRingLMH);
            if (lmh != null)
                Logging.AddLogMessageHandlerToDefaultDistributionGroup(lmh);

            // how to change wpfLMH logging level after construction
            if (wpfLMH != null)
                Logging.AddLogMessageHandlerToDefaultDistributionGroup(wpfLMH);

            appLogger = new Logging.Logger("AppLogger");
            Logging.LogMessage lm = appLogger.GetLogMessage(Logging.MesgType.Signif, "App Starting", appLogger.GetStackFrame(0));
            lm.KeywordArray = new string[] { "Application", "OnStartup" };
            appLogger.EmitLogMessage(ref lm);

            // emit the config messages obtained above.
            Logging.Logger appLoggerCopy = appLogger;
            issueListEmitter.EmittedItemList.ForEach((item) => appLoggerCopy.Error.Emit(item.MesgStr));
            valuesListEmitter.EmittedItemList.ForEach((item) => appLoggerCopy.Debug.Emit(item.MesgStr));

            // setup the loadPortTraceGroup - to recieve trace data from
            string traceLoggingGroupName = "LGID.Trace";

            Logging.ILogMessageHandler traceRingLMH = Logging.CreateQueuedTextFileRotationDirectoryLogMessageHandler(traceRingConfig);

            Logging.AddLogMessageHandlerToDistributionGroup(traceLoggingGroupName, traceRingLMH);
            Logging.SetDistributionGroupGate(traceLoggingGroupName, Logging.LogGate.All);

            Logging.LinkDistributionToGroup(Logging.DefaultDistributionGroupName, traceLoggingGroupName);
            Logging.MapLoggersToDistributionGroup(Logging.LoggerNameMatchType.Regex, @"(\.Data|\.Trace)", traceLoggingGroupName);
        }
Пример #3
0
        public static void HandleOnStartup(StartupEventArgs e, ref Logging.Logger appLogger)
        {
            string logBaseName = System.Reflection.Assembly.GetCallingAssembly().FullName.Split(',').SafeAccess(0);        // split off the "name" of the assembly from the other parts that make up its "full" name.

            HandleOnStartup(e, ref appLogger, logBaseName);
        }
Пример #4
0
 public static void HandleOnDeactivated(Logging.ILogger appLogger)
 {
     Logging.LogMessage lm = appLogger.GetLogMessage(Logging.MesgType.Signif, "App Deactiviated", appLogger.GetStackFrame(0));
     lm.KeywordArray = new string[] { "Application", "OnDeactivated" };
     appLogger.EmitLogMessage(ref lm);
 }
Пример #5
0
            /// <summary>
            /// Use this method to read the stock set of ModularConfig points using the given configKeyPrefixStr and to update this ring configuration using the valid, non-zero values read from these keys.
            /// <para/>Keys are LogGate, DirectoryPath, MaxFilesToKeep, MaxFileAgeToKeepInDays, MaxTotalSizeToKeep, AdvanceAfterFileReachesSize, AdvanceAfterFileReachesAge
            /// </summary>
            public FileRotationLoggingConfig UpdateFromModularConfig(string configKeyPrefixStr, Logging.IMesgEmitter issueEmitter, Logging.IMesgEmitter valueEmitter)
            {
                ConfigValueSetAdapter<ConfigKeyValuesHelper> adapter = new ConfigValueSetAdapter<ConfigKeyValuesHelper>() { ValueSet = new ConfigKeyValuesHelper(), SetupIssueEmitter = issueEmitter, ValueNoteEmitter = valueEmitter }.Setup(configKeyPrefixStr);

                ConfigKeyValuesHelper configValues = adapter.ValueSet;

                logGate |= configValues.LogGate;

                if (!String.IsNullOrEmpty(configValues.DirectoryPath))
                    dirPath = configValues.DirectoryPath;

                if (configValues.MaxFilesToKeep != 0)
                    purgeRules.dirNumFilesLimit = configValues.MaxFilesToKeep;
                if (configValues.MaxFileAgeToKeep != TimeSpan.Zero)
                    purgeRules.FileAgeLimit = configValues.MaxFileAgeToKeep;
                if (configValues.MaxTotalSizeToKeep != 0)
                    purgeRules.dirTotalSizeLimit = configValues.MaxTotalSizeToKeep;

                if (configValues.AdvanceAfterFileReachesSize != 0)
                    advanceRules.fileSizeLimit = configValues.AdvanceAfterFileReachesSize;
                if (configValues.AdvanceAfterFileReachesAge != TimeSpan.Zero)
                    advanceRules.FileAgeLimit = configValues.AdvanceAfterFileReachesAge;

                return this;
            }