Why is my EventSource not registering?

I use the Semantic Logging Application Block, and I have the following two classes based on EventSource (internal constant classes are omitted for brevity:

[EventSource(Name = EventSourceNames.Prism)]
public sealed class PrismEventSource: EventSource
{
  public static PrismEventSource Log = new PrismEventSource();
  [Event(1, Keywords = EventKeywords.None, Level = EventLevel.Informational)]
  public void PrismEvent(string message, Category category, Priority priority)
  {
    if (IsEnabled())
    {
      WriteEvent(1, message, category);
    }
  }
}

and

[EventSource(Name = EventSourceNames.Application)]
public sealed class ApplicationEventSource : EventSource
{
  public static ApplicationEventSource Log = new ApplicationEventSource();
  [Event(2, Message = "Duplicate menu item: {0}", Keywords = Keywords.Menu, Level = EventLevel.LogAlways, Task = Tasks.ImportMenu)]
  public void DuplicateMenuItem(string menuItemPath)
  {
    if (IsEnabled())
    {
      WriteEvent(2, menuItemPath);
    }
  }
}

I have one widescreen project listener for both:

RollingLog = RollingFlatFileLog.CreateListener("XTimeDev.log", 2048, "yyyyMMdd HHmmss", RollFileExistsBehavior.Overwrite, RollInterval.None);
RollingLog.EnableEvents(EventSourceNames.Prism, EventLevel.LogAlways);
RollingLog.EnableEvents(EventSourceNames.Application, EventLevel.LogAlways);

However, when I try to log in from my application source, nothing is displayed in the log file:

try
{
  Current.RegisterMenuItem(xtimeItem);
}
catch (ArgumentException ax)
{
  ApplicationEventSource.Log.DuplicateMenuItem(ax.Message);
} 

All that I see in my log file are trigger events. Prism records his source of events, the one I give him in MefBootstrapper.CreateLogger:

class BootLogger : ILoggerFacade
{
  public void Log(string message, Category category, Priority priority)
  {
    PrismEventSource.Log.PrismEvent(message, category, priority);
  }
}

Why should the file be written only PrismEventSource, and not ApplicationEventSource?

+4
source share
1 answer

, WriteEvent.

, :

public void PrismEvent(string message, Category category, Priority priority)
{
  if (IsEnabled())
  {
    WriteEvent(1, message, category, priority);
    //                                 ^  ^
  }
}

.


, , unit test, EventSourceAnalyzer. , .

+3

Source: https://habr.com/ru/post/1536715/


All Articles