private void LogToFile() { var listener = RollingFlatFileLog.CreateListener("logfile.txt", 5, "yyyyMMddHHmmss", Microsoft.Practices.EnterpriseLibrary.SemanticLogging.Sinks.RollFileExistsBehavior.Overwrite, Microsoft.Practices.EnterpriseLibrary.SemanticLogging.Sinks.RollInterval.Day, maxArchivedFiles: 5, formatter: new EventTextFormatter()); listener.EnableEvents(MyEventSource.Log, EventLevel.LogAlways, EventKeywords.All); foreach (var i in Enumerable.Range(1, 1000)) { MyEventSource.Log.MethodOne("aaabbbccc", "ddd", "eee"); MyEventSource.Log.MethodTwo(3.14); MyEventSource.Log.MethodThree("def"); } listener.DisableEvents(MyEventSource.Log); listener.Dispose(); }
private void LogToFileAdvanced() { var listener = RollingFlatFileLog.CreateListener("logfileadv.txt", 5, "yyyyMMddHHmmss", Microsoft.Practices.EnterpriseLibrary.SemanticLogging.Sinks.RollFileExistsBehavior.Overwrite, Microsoft.Practices.EnterpriseLibrary.SemanticLogging.Sinks.RollInterval.Day, maxArchivedFiles: 5, formatter: new EventTextFormatter()); listener.EnableEvents(EventSourceSelfDescribing.Log, EventLevel.LogAlways, EventKeywords.All); foreach (var i in Enumerable.Range(1, 1000)) { EventSourceSelfDescribing.Log.MethodOne("aaabbbccc", new[] { "ddd", "eee" }); EventSourceSelfDescribing.Log.ActivityStart("Starting child activity"); EventSourceSelfDescribing.Log.MethodTwo(3.14, new Dictionary <string, int> { { "twentyone", 21 }, { "twentytwo", 22 } }); EventSourceSelfDescribing.Log.ActivityStop("Stopping child activity"); EventSourceSelfDescribing.Log.MethodThree("def", new MyEventData { PropertyOne = "p1", Texts = new[] { "text1", "text2" } }); } listener.DisableEvents(EventSourceSelfDescribing.Log); listener.Dispose(); }