我正在使用语义日志记录应用程序块,并且我有以下两个基于 EventSource 的类(为简洁起见,省略了内部常量类:
[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);
}
}
}
和
[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);
}
}
}
我有一个项目范围的单例监听器:
RollingLog = RollingFlatFileLog.CreateListener("XTimeDev.log", 2048, "yyyyMMdd HHmmss", RollFileExistsBehavior.Overwrite, RollInterval.None);
RollingLog.EnableEvents(EventSourceNames.Prism, EventLevel.LogAlways);
RollingLog.EnableEvents(EventSourceNames.Application, EventLevel.LogAlways);
然而,当我尝试从我的应用程序源登录时,日志文件中没有任何内容:
try
{
Current.RegisterMenuItem(xtimeItem);
}
catch (ArgumentException ax)
{
ApplicationEventSource.Log.DuplicateMenuItem(ax.Message);
}
我在日志文件中看到的只是启动事件 Prism 通过其事件源记录的事件源,即我提供的事件源MefBootstrapper.CreateLogger
:
class BootLogger : ILoggerFacade
{
public void Log(string message, Category category, Priority priority)
{
PrismEventSource.Log.PrismEvent(message, category, priority);
}
}
为什么只应该PrismEventSource
而不是ApplicationEventSource
写入文件?