internal void RaiseOnLog(LogMessageSeverity severity, LogMessageSource source, string message) { if (LogMessage != null) { RaiseEvent(nameof(LogMessage), () => LogMessage(this, new LogMessageEventArgs(severity, source, message))); } }
/// <summary> /// Write the provided logging event to the central Gibraltar log. /// </summary> /// <remarks> /// <para>The central Gibraltar logging class (Log) makes common decisions about when to write out logging information /// and where to write it out, therefore not all Log4Net logging events may be chosen to be permanently recorded</para> /// <para>Required as part of the Log4Net IAppender interface implementation.</para></remarks> /// <param name="loggingEvent">The individual LoggingEvent to be appended.</param> protected override void Append(LoggingEvent loggingEvent) { // We shouldn't need a lock in this method because we don't access any of our member variables here, // and we don't need a recursion-guard because we don't send our own log events through log4net. // But we do need to first make sure the information we need is available from the LoggingEvent. // If it hasn't had any Fix flags set then we should be clear to access them without doing a Fix. const FixFlags ourFixFlags = FixFlags.Message | FixFlags.LocationInfo // | FixFlags.UserName | FixFlags.Identity | FixFlags.Exception; FixFlags fixedFlags = loggingEvent.Fix; if (fixedFlags != FixFlags.None) { // Hmmm, someone already did a Fix on this LoggingEvent, which apparently locks other values from // being updated upon reference. So we need to make sure the ones we need are also "fixed". // But don't do this if the flags are None because we don't want to lock the loggingEvent against // being updated by other references if it isn't already. // ToDo: Find out if this is actually necessary or if we are guaranteed to get our own LoggingEvent // independent of any other appender. It seems odd that appenders could break each other this way. FixFlags neededFlags = ourFixFlags & ~fixedFlags; // What we need which isn't already fixed if (neededFlags != FixFlags.None) { // Uh-oh, there's something we do need to have "fixed" loggingEvent.Fix = ourFixFlags; // should we set both (ourFixFlags | FixFlags.Partial) ? // Flags that were already set are ignored in the new value, they can't change back to 0. } } LocationInfo locationInfo = loggingEvent.LocationInformation; IMessageSourceProvider messageSource = new LogMessageSource(locationInfo); // Wrap it with our converter Exception exception = loggingEvent.ExceptionObject; string loggerName = loggingEvent.LoggerName; string message = Layout != null?RenderLoggingEvent(loggingEvent) : loggingEvent.RenderedMessage; string userName = loggingEvent.Identity; if (string.IsNullOrEmpty(userName)) { // No thread-specific impersonating user, we'll just get the invariant process username later; userName = null; } // This is a slight hack. We get our repository from the first LoggingEvent we see after a config update // and use it to update our thresholds configuration. We are assuming each instance of an appender is // associated with only one repository (but might in general be attached to multiple loggers). // Notice that GibraltarMessageSeverity() will get the lock for access to our threshold config member variables. LogMessageSeverity severity = GibraltarMessageSeverity(loggingEvent.Level, loggingEvent.Repository); if (severity != LogMessageSeverity.None) // Filter out severities less than configured Verbose threshold { // We have a real event message. Log it to the central Gibraltar queue, tagged as from Log4Net Log.Write(severity, "Log4Net", messageSource, userName, exception, LogWriteMode.Queued, null, loggerName, null, message); } }
public LogMessage(LogMessageSource messageSource, int readPosition, string msg) : this(messageSource, msg) { position = readPosition; }
public LogMessage(LogMessageSource messageSource, string msg) { source = messageSource; message = msg; }
public LogMessage() { source = LogMessageSource.Audio; time = GlobalTimer.GetInstance().GetTime(); position = -1; }
internal LogMessageEventArgs(LogMessageSeverity severity, LogMessageSource source, string msg) { Severity = severity; Source = source; Message = msg; }
private void ApplicationIdIsSet() { var source = new LogMessageSource("appid", "componentid"); Assert.Equal("appid", source.ApplicationId); }
private void ComponentIdIsSet() { var source = new LogMessageSource("appid", "componentid"); Assert.Equal("componentid", source.ComponentId); }
internal void RaiseOnLog(LogMessageSeverity severity, LogMessageSource source, string message) { if (LogMessage != null) RaiseEvent(nameof(LogMessage), () => LogMessage(this, new LogMessageEventArgs(severity, source, message))); }
public LogMessage() { source = LogMessageSource.Audio; }
public LogMessage(LogMessageSource messageSource, long messageTime, string readPosition, string msg) : this(messageSource, messageTime, msg) { position = readPosition; }
public LogMessage(LogMessageSource messageSource, long messageTime, string msg) : this(messageSource, msg) { time = messageTime; }