我正在尝试使用 .Net 4.5、语义日志记录 (SLAB) EventSource 来创建带有自定义关键字的事件。我想使用进程外,并使用关键字将事件引导到日志文件或 SQL。我在单独的测试中对这个类使用了 EventSourceAnalyzer,没有例外。
我可以通过使用不同的“EventLevel”将事件“引导”到不同的接收器,但我更喜欢使用自定义关键字进行路由。
这是课堂——
public class XYZWebLog : EventSource
{
public class Keywords
{
public const EventKeywords Login = (EventKeywords)2;
public const EventKeywords Billing = (EventKeywords)4;
}
[Event(1, Level = EventLevel.Informational, Keywords = Keywords.Login)]
public void SuccessfulLogin(string loginId) { WriteEvent(1, loginId); }
[Event(2, Level = EventLevel.Informational, Keywords = Keywords.Login)]
public void UnSuccessfulLogin(string loginId){ WriteEvent(2, loginId); }
[Event(3, Level = EventLevel.Informational, Keywords = Keywords.Login)]
public void Logout(string loginId) { WriteEvent(3, loginId); }
[Event(4, Level = EventLevel.Informational, Keywords = Keywords.Billing)]
public void BillAudit(string UserId, string Action, string VisitId, string BillingID, string Details) { WriteEvent(4, UserId, Action, VisitId, BillingID, Details); }
private static XYZWebLog _log = new XYZWebLog();
private XYZWebLog() {}
public static XYZWebLog Log { get { return _log; } }
}
然后这里是 SemanticLogging-svc.exe 的配置:
<!-- Sinks reference definitons used by this host to listen ETW events -->
<flatFileSink name="svcRuntime" fileName="Billing.log" >
<sources>
<eventSource name="XYZWebLog" level="Informational" matchAnyKeyword="4" />
</sources>
<eventTextFormatter header="----------"/>
</flatFileSink>
<flatFileSink name="loginLogs" fileName="Login-Logout.log" >
<sources>
<eventSource name="XYZWebLog" level="Informational" matchAnyKeyword="2" />
</sources>
<eventTextFormatter header="++++++++++"/>
</flatFileSink>
如果我删除“matchAnyKeyword”,并正确设置级别,我可以让事件进入不同的文件——我已经尝试过“2”和“0x002”,以及其他关于定义我能想到的自定义事件的事情. 我在网上搜索并研究了我能找到哪些文档。