示例#1
0
                /// <summary>
                /// Multiple targetLMH constructor.  Derives LoggingConfig values from the given targetLMH
                /// </summary>
                /// <param name="name">Gives the name of this LMH - different than the names of the target LMH instances</param>
                /// <param name="targetLMHArray">Gives the set of LMH instance that are to be given the dequeued LogMessages.</param>
                /// <param name="maxQueueSize">Defines te maximum number of messages that can be held internally before messages are lost.</param>
                /// <param name="allowRecordSourceStackFrame">The use of this parameter is now obsolete and will be ignored</param>
                public QueueLogMessageHandler(string name, ILogMessageHandler[] targetLMHArray, int maxQueueSize = DefaultMesgQueueSize, bool allowRecordSourceStackFrame = false)
                    : base(name, LogGate.None, recordSourceStackFrame: false)
                {
                    targetLMHArray = targetLMHArray ?? emptyLMHArray;

                    LogGate logGate = LogGate.None;

                    foreach (ILogMessageHandler targetLMH in targetLMHArray)
                    {
                        logGate.MesgTypeMask |= targetLMH.LoggerConfig.LogGate.MesgTypeMask;
                    }

                    loggerConfig.LogGate = logGate;

                    this.targetLMHArray = targetLMHArray;

                    mesgDeliveryList = new List <LogMessage>(10);                // define its initial capacity

                    mesgQueue = new MessageQueue(maxQueueSize);
                    mesgQueue.SetEffectiveSourceInfo(logger.LoggerSourceInfo);
                    mesgQueue.EnableQueue();
                    mesgQueueMutex = mesgQueue.Mutex;

                    // create and start the thread
                    StartIfNeeded();
                }
示例#2
0
            /// <summary>Detailed Constructor.  Uses given logger name, group name, and initialInstanceLogGate.  Use default group name and enables instance trace logging</summary>
            /// <param name="name">Provides the LoggerName (source ID) to use for this logger.</param>
            /// <param name="groupName">Provides the GroupName that this logger name will be assigned/moved to</param>
            /// <param name="initialInstanceLogGate">Defines the initial instance group gate that may be more restrictive than the gate assigned to the group or the logger through the distribution system.</param>
            /// <param name="callerProvidedLMD">can be used to define the ILogMessageDistribution instance that this object will be used with</param>
            public QueuedLogger(string name, string groupName, LogGate initialInstanceLogGate, ILogMessageDistribution callerProvidedLMD = null)
                : base(name, groupName, initialInstanceLogGate, callerProvidedLMD: callerProvidedLMD)
            {
                dist4q = callerProvidedLMD ?? Logging.LogMessageDistribution.Instance;

                if (dist4q == null)
                {
                    Utils.Asserts.TakeBreakpointAfterFault("{0}: LogMessageDistribution is null".CheckedFormat(ClassName));
                }

                if (dist4q != null)
                {
                    dist4q.StartQueuedMessageDeliveryIfNeeded();
                }
            }
 /// <summary>Creates a SimpleFileLogMessageHandler to write to the given filePath, and given LogGate value.  Optionally includes files and line numbers.  lmh name is "LMH." + filePath</summary>
 public static ILogMessageHandler CreateSimpleFileLogMessageHandler(string filePath, bool includeFileAndLines, LogGate logGate)
 {
     return new Handlers.SimpleFileLogMessageHandler(filePath, includeFileAndLines, logGate);
 }
示例#4
0
 /// <summary>Sets a gate level for messages to a given group so that it may be more restritive than that of the most permissive handler that is attached to the group.</summary>
 public static void SetDistributionGroupGate(string groupName, LogGate logGate)
 {
     GetLogMessageDistributionImpl().SetDistributionGroupGate(groupName, logGate);
 }
            /// <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;
            }
 /// <summary>Basic constructor.</summary>
 /// <param name="name">Defines the LMH name.</param>
 /// <param name="logGate">Defines the LogGate value for messages handled here.  Messages with MesgType that is not included in this gate will be ignored.</param>
 /// <param name="lineFmt">Gives the line formatting rules that will be used for this LMH</param>
 public ConsoleLogMesssageHandler(string name, LogGate logGate, LineFormat lineFmt)
     : base(name, logGate, lineFmt, new System.IO.StreamWriter(Console.OpenStandardOutput()), true)
 {
 }
 /// <summary>Creates a ConsoleLogMessageHandler named "LMH.Console" with given logGate</summary>
 public static ILogMessageHandler CreateConsoleLogMessageHandler(LogGate logGate)
 {
     return CreateConsoleLogMessageHandler("LMH.Console", logGate);
 }
 /// <summary>Simple constructor: uses default settings of 2000 files in ring, 1000000 byes per file, DefaultMesgQueueSize</summary>
 public FileRotationLoggingConfig(string name, string dirPath, LogGate logGate)
     : this(name, dirPath, logGate, 2000, 1000000, DefaultMesgQueueSize)
 {
 }
                /// <summary>Basic constructor.</summary>
                /// <param name="name">Defines the LMH name.</param>
                /// <param name="logGate">Defines the LogGate value for messages handled here.  Messages with MesgType that is not included in this gate will be ignored.</param>
                /// <param name="lineFmt">Gives the line formatting rules that will be used for this LMH</param>
                /// <param name="ostream">Gives the StreamWriter instance to which the output text will be written.</param>
                /// <param name="flushAfterEachWrite">Set to true to flush the ostream after each write, or false to Flush only when explicitly told to by the LogDistribution system.</param>
                public StreamWriterLogMessageHandlerBase(string name, LogGate logGate, LineFormat lineFmt, System.IO.StreamWriter ostream, bool flushAfterEachWrite)
                    : base(name, logGate, lineFmt.IncludeFileAndLine, true)
                {
                    this.lineFmt = lineFmt;
                    this.ostream = ostream;
                    this.flushAfterEachWrite = flushAfterEachWrite;

                    if (lineFmt == null)
                        Utils.Asserts.TakeBreakpointAfterFault("LineFmt is null");
                    if (ostream == null)
                        Utils.Asserts.TakeBreakpointAfterFault("ostream is null");

                    // add an action to close the ostream when this object is disposed.
                    AddExplicitDisposeAction(
                        () =>
                        {
                            if (this.ostream != null)
                            {
                                this.ostream.Close();
                                this.ostream = null;
                            }
                        });
                }
示例#10
0
 /// <summary>Basic constructor.</summary>
 /// <param name="appName">Gives the name of the appication that will be used as a prefix for the debug log messages that are generated</param>
 /// <param name="name">Defines the LMH name.</param>
 /// <param name="logGate">Defines the LogGate value for messages handled here.  Messages with MesgType that is not included in this gate will be ignored.</param>
 public Win32DebugLogMessageHandler(string appName, string name, LogGate logGate)
     : base(name, logGate, false, true)
 {
     this.appName = appName;
     this.lineFmt = new LineFormat(false, true, true, true, true, false, "\n", " ");
     if (String.IsNullOrEmpty(appName))
         Utils.Asserts.TakeBreakpointAfterFault("AppName is empty");
 }
示例#11
0
 /// <summary>Basic constructor.</summary>
 /// <param name="name">Defines the LMH name.</param>
 /// <param name="logGate">Defines the LogGate value for messages handled here.  Messages with MesgType that is not included in this gate will be ignored.</param>
 /// <param name="includeFileAndLines">Indicates if this handler should record and save source file and line numbers.</param>
 /// <param name="supportReferenceCountedRelease">Indicates if this logger supports reference counted log message release.</param>
 public SimpleLogMessageHandlerBase(string name, LogGate logGate, bool includeFileAndLines, bool supportReferenceCountedRelease)
     : base(name, logGate, includeFileAndLines, supportReferenceCountedRelease)
 {
 }
示例#12
0
                /// <summary>Basic constructor.</summary>
                /// <param name="filePath">Gives the path to the file name to which log messages will be appended.  Also used to name the LMH instance as "LMH." + filePath</param>
                /// <param name="includeFileAndLines">Indicates if this handler should record and include source file and line numbers.</param>
                /// <param name="logGate">Defines the LogGate value for messages handled here.  Messages with MesgType that is not included in this gate will be ignored.</param>
                public SimpleFileLogMessageHandler(string filePath, bool includeFileAndLines, LogGate logGate)
                    : base("LMH." + filePath, logGate, 
							new LineFormat(true, true, true, true, includeFileAndLines), 
							new System.IO.StreamWriter(filePath, true, System.Text.Encoding.ASCII),
							false)
                {
                    if (ostream.BaseStream.CanWrite)
                        ostream.Write("\r\n");

                    logger.Signif.Emit("----------------------------------------");
                    logger.Signif.Emit("LogMessageHandler starting: File has been opened");
                }
示例#13
0
 /// <summary>Basic constructor.</summary>
 /// <param name="name">Defines the LMH name.</param>
 /// <param name="logGate">Defines the LogGate value for messages handled here.  Messages with MesgType that is not included in this gate will be ignored.</param>
 /// <param name="includeFileAndLines">Indicates if this handler should record and include source file and line numbers.</param>
 public NullLogMessageHandler(string name, LogGate logGate, bool includeFileAndLines)
     : base(name, logGate, includeFileAndLines, true)
 {
 }
示例#14
0
 /// <summary>Creates a Win32DebugLogMessageHandler named "LMH.Debug" with given logGate</summary>
 /// <remarks>appName is used to prefix all messages that are sent to the debugger</remarks>
 public static ILogMessageHandler CreateWin32DebugLogMessageHandler(string appName, LogGate logGate)
 {
     return CreateWin32DebugLogMessageHandler(appName, "LMH.Debug", logGate);
 }
示例#15
0
 /// <summary>Creates a ConsoleLogMessageHandler given name and logGate</summary>
 public static ILogMessageHandler CreateConsoleLogMessageHandler(string name, LogGate logGate)
 {
     return new Handlers.ConsoleLogMesssageHandler(name, logGate, new Handlers.LineFormat(false, true, true, " "));
 }
示例#16
0
 /// <summary>Creates a Win32DebugLogMessageHandler given name and logGate</summary>
 /// <remarks>appName is used to prefix all messages that are sent to the debugger</remarks>
 public static ILogMessageHandler CreateWin32DebugLogMessageHandler(string appName, string name, LogGate logGate)
 {
     return new Handlers.Win32DebugLogMessageHandler(appName, name, logGate);
 }
示例#17
0
 /// <summary>Creates a DiagnosticTraceLogMessageHandler named "LMH.DiagnosticTrace" with given logGate</summary>
 public static ILogMessageHandler CreateDiagnosticTraceLogMessageHandler(LogGate logGate)
 {
     return CreateDiagnosticTraceLogMessageHandler("LMH.DiagnosticTrace", logGate);
 }
示例#18
0
            /// <summary>Standard constructor</summary>
            public FileRotationLoggingConfig(string name, string dirPath, LogGate logGate, int maxFilesInRing, int advanceAfterFileSize, int mesgQueueSize)
                : this()
            {
                this.name = name;
                this.dirPath = dirPath;
                this.logGate = logGate;
                this.mesgQueueSize = mesgQueueSize;
                this.nameUsesDateAndTime = true;
                this.includeFileAndLine = true;
                this.includeQpcTime = true;

                this.advanceRules = new AdvanceRules();
                this.purgeRules = new PurgeRules();

                purgeRules.dirNumFilesLimit = maxFilesInRing;
                advanceRules.fileSizeLimit = advanceAfterFileSize;
                advanceRules.fileAgeLimitInSec = 24.0 * 3600.0;		// 1 day

                excludeFileNamesSet = new List<string>();

                createDirectoryIfNeeded = true;
            }
示例#19
0
 /// <summary>Creates a DiagnosticTraceLogMessageHandler given name and logGate</summary>
 public static ILogMessageHandler CreateDiagnosticTraceLogMessageHandler(string name, LogGate logGate)
 {
     return new Handlers.DiagnosticTraceLogMessageHandler(name, logGate, new Handlers.LineFormat(false, true, true, true, true, false, "", " "));
 }
示例#20
0
                /// <summary>Basic constructor.</summary>
                /// <param name="name">Defines the LMH name.</param>
                /// <param name="logGate">Defines the LogGate value for messages handled here.  Messages with MesgType that is not included in this gate will be ignored.</param>
                /// <param name="includeFileAndLines">Indicates if this handler should record and save source file and line numbers.</param>
                /// <param name="supportReferenceCountedRelease">Indicates if this logger supports reference counted log message release.</param>
                public CommonLogMessageHandlerBase(string name, LogGate logGate, bool includeFileAndLines, bool supportReferenceCountedRelease)
                {
                    this.name = name;
                    loggerConfig = new LoggerConfig() { GroupName = "LMH:" + name, LogGate = logGate, RecordSourceStackFrame = includeFileAndLines, SupportsReferenceCountedRelease = supportReferenceCountedRelease };

                    logger = new LogMesgHandlerLogger(this);
                }
示例#21
0
 /// <summary>Creates a NullLogMessageHandler named "LMH.Null" with given logGate</summary>
 public static ILogMessageHandler CreateNullLogMessageHandler(LogGate logGate)
 {
     return CreateNullLogMessageHandler("LMH.Null", logGate);
 }
示例#22
0
 /// <summary>Basic constructor.</summary>
 /// <param name="name">Defines the LMH name.</param>
 /// <param name="logGate">Defines the LogGate value for messages handled here.  Messages with MesgType that is not included in this gate will be ignored.</param>
 /// <param name="lineFmt">Gives the line formatting rules that will be used for this LMH</param>
 public DiagnosticTraceLogMessageHandler(string name, LogGate logGate, LineFormat lineFmt)
     : base(name, logGate, false, true)
 {
     this.lineFmt = lineFmt;
 }
示例#23
0
 /// <summary>Creates a NullLogMessageHandler given name and logGate</summary>
 public static ILogMessageHandler CreateNullLogMessageHandler(string name, LogGate logGate)
 {
     return new Handlers.NullLogMessageHandler(name, logGate, false);
 }
示例#24
0
 /// <summary>Sets the group gate level for the default distribution group.</summary>
 public static void SetDefaultDistributionGroupGate(LogGate logGate)
 {
     SetDistributionGroupGate(DefaultDistributionGroupName, logGate);
 }
示例#25
0
 /// <summary>Creates a SimpleFileLogMessageHandler to write to the given filePath, does not include files and lines, uses given LogGate.  lmh name is "LMH." + filePath</summary>
 public static ILogMessageHandler CreateSimpleFileLogMessageHandler(string filePath, LogGate logGate)
 {
     return CreateSimpleFileLogMessageHandler(filePath, false, logGate);
 }
示例#26
0
            public void SetDistributionGroupGate(string groupName, LogGate logGate)
            {
                lock (distMutex)
                {
                    int dgid = InnerGetDistGroupID(groupName, true);

                    if (!InnerIsDistGroupIDValid(dgid))
                    {
                        Utils.Asserts.TakeBreakpointAfterFault("SetDistributionGroupGate::Given GroupName could not be created.");
                        return;
                    }

                    PerDistGroupIDInfo dgInfo = distGroupIDInfoList [dgid];

                    // read the LoggerConfig (struct), update the LogGate field and then write it back to the PerDistGroupIDInfo so that it can notify observers of the change.
                    LoggerConfig lc = dgInfo.GroupLoggerConfigSetting;
                    lc.LogGate = logGate;
                    dgInfo.GroupLoggerConfigSetting = lc;

                    if (dgInfo.UpdateActiveLoggerConfig())
                        InnerUpdateLoggerDistGroupConfigForGroup(dgid);
                }
            }
示例#27
0
 /// <summary>Constructor.  Uses given logger name, and initialInstanceLogGate.  Enables instance trace logging</summary>
 /// <param name="name">Provides the LoggerName (source ID) to use for this logger.</param>
 /// <param name="initialInstanceLogGate">Defines the initial instance group gate that may be more restrictive than the gate assigned to the group or the logger through the distribution system.</param>
 public QueuedLogger(string name, LogGate initialInstanceLogGate)
     : this(name, string.Empty, initialInstanceLogGate)
 {
 }