0

我已经迁移到带有语义日志记录的 Enterprise Library 6。它适用于进程内日志记录,但我无法让进程外日志记录工作。SemanticLogging SVC 作为 Windows 服务启动,我知道它工作正常,因为由于错误“Semantic-SVC 服务正在使用文件”,我无法删除配置的日志文件。此外,如果我更改 SemanticLogging-svc.xml 中的文件名,它会重新创建一个新文件。但是日志文件只是空的。我正在使用https://msdn.microsoft.com/en-us/library/dn440729%28v=pandp.60%29.aspx中的示例。我打电话给 MyCompanyEvents.Log.Startup。MatchAnyKeyword 设置为 12,Level 为“always”,因此它应该记录 Startup 消息。有任何想法吗?


[EventSource(Name = "MyCompany")]
public class MyCompanyEventSource : EventSource
{
public class Keywords
{
    public const EventKeywords Page = (EventKeywords)1;
    public const EventKeywords DataBase = (EventKeywords)2;
    public const EventKeywords Diagnostic = (EventKeywords)4;
    public const EventKeywords Perf = (EventKeywords)8;
}

public class Tasks
{
    public const EventTask Page = (EventTask)1;
    public const EventTask DBQuery = (EventTask)2;
}

private static MyCompanyEventSource _log = new MyCompanyEventSource();
private MyCompanyEventSource() { }
public static MyCompanyEventSource Log { get { return _log; } }

[Event(1, Message = "Application Failure: {0}", 
Level = EventLevel.Critical, Keywords = Keywords.Diagnostic)]
internal void Failure(string message)
{
  this.WriteEvent(1, message);
}

[Event(2, Message = "Starting up.", Keywords = Keywords.Perf,
Level = EventLevel.Informational)]
internal void Startup()
{
  this.WriteEvent(2);
}

[Event(3, Message = "loading page {1} activityID={0}",
Opcode = EventOpcode.Start,
Task = Tasks.Page, Keywords = Keywords.Page,
Level = EventLevel.Informational)]
internal void PageStart(int ID, string url)
{
  if (this.IsEnabled()) this.WriteEvent(3, ID, url);
}


...
}



<?xml version="1.0"?>
<configuration
xmlns=http://schemas.microsoft.com/practices/2013/entlib/semanticlogging/etw
xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance
xsi:schemaLocation="http://schemas.microsoft.com/practices/2013/entlib/
semanticlogging/etw SemanticLogging-svc.xsd">
<!-- Optional settings for this host -->
<traceEventService/>
<!-- Event sink definitions used by this host to
listen ETW events emitted by these EventSource instances -->
<sinks>
<consoleSink name="ConsoleEventSink">
  <sources>
    <eventSource name="MyCompany" level="LogAlways" matchAnyKeyword="12"/>
  </sources>
  <eventTextFormatter header="+=========================================+"/>
</consoleSink>

<rollingFlatFileSink name="RollingFlatFileSink" 
                     fileName="c:\\logs\\RollingFlatFile.log" 
                     timeStampPattern="yyyy" 
                     rollFileExistsBehavior="Overwrite" 
                     rollInterval="Day">
  <sources>
    <eventSource name="MyCompany"
                 level="LogAlways" matchAnyKeyword="12"/>
  </sources>
</rollingFlatFileSink>

4

0 回答 0