私はセマンティック ログ アプリケーション ブロックを使用しており、次の 2 つの 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
のですか?