本文整理汇总了C#中ObservableEventListener.DisableEvents方法的典型用法代码示例。如果您正苦于以下问题:C# ObservableEventListener.DisableEvents方法的具体用法?C# ObservableEventListener.DisableEvents怎么用?C# ObservableEventListener.DisableEvents使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObservableEventListener
的用法示例。
在下文中一共展示了ObservableEventListener.DisableEvents方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: With1Listener
public static void With1Listener(IEnumerable<EventSource> loggers, Action<ObservableEventListener, InMemoryEventListener> scenario)
{
using (var errorsListener = new InMemoryEventListener())
using (var listener = new ObservableEventListener())
{
try
{
errorsListener.EnableEvents(SemanticLoggingEventSource.Log, EventLevel.Verbose, Keywords.All);
scenario(listener, errorsListener);
}
finally
{
foreach (var logger in loggers)
{
try
{ listener.DisableEvents(logger); }
catch
{ }
}
errorsListener.DisableEvents(SemanticLoggingEventSource.Log);
}
}
}
示例2: TestExporter
public void TestExporter() {
var listener = new ObservableEventListener();
listener.EnableEvents(TflEventSource.Log, EventLevel.Verbose);
var subscription = listener.LogToConsole(new LegacyLogFormatter());
var file = Path.GetTempFileName();
File.WriteAllText(file, @"t1,t2,t3,t4
Monday,10,1.1,1/1/2014
Tuesday,11,2.2,2/1/2014
Wednesday,12,3.3,3/1/2014
Wednesday,12,3.3,3/1/2014
Thursday,13,4.4,4/1/2014
Friday,14,5.5,5/1/2014
Saturday,15,6.6,6/1/2014");
File.Delete(OUTPUT);
var profile = new Profiler().Profile(file);
new ProfileExporter().Export(profile, OUTPUT);
subscription.Dispose();
listener.DisableEvents(TflEventSource.Log);
listener.Dispose();
Assert.IsTrue(File.Exists(OUTPUT));
}
示例3: Main
static void Main(string[] args) {
var listener = new ObservableEventListener();
listener.EnableEvents(TflEventSource.Log, EventLevel.Informational);
var subscription = listener.LogToConsole(new LegacyLogFormatter());
ValidateArguments(args);
new ProfileExporter().Export(new Profiler().Profile(_input, _sample), _output);
subscription.Dispose();
listener.DisableEvents(TflEventSource.Log);
listener.Dispose();
}
示例4: Main
static void Main(string[] args)
{
ObservableEventListener listener = new ObservableEventListener();
listener.EnableEvents(MyCompanyEventSource.Log, EventLevel.LogAlways, Keywords.All);
listener.LogToConsole();
// Modify these settings to match your SMTP service requirements.
listener.LogToEmail("smtp.live.com", 587, "[email protected]", "In Proc Sample", "etw");
MyCompanyEventSource.Log.Failure("No response from servers, general network failure!!");
listener.DisableEvents(MyCompanyEventSource.Log);
listener.Dispose();
}
示例5: SimpleEventSource
static void SimpleEventSource()
{
// Set up and enable the event listener - typically done when the application starts
var listener = new ObservableEventListener();
listener.LogToConsole();
listener.EnableEvents(MyCompanyEventSource.Log, EventLevel.LogAlways, Keywords.All);
// Log some messages
MyCompanyEventSource.Log.Startup();
MyCompanyEventSource.Log.Failure("Couldn't connect to server.");
Console.WriteLine("Written two log messages.\nUsing a basic console listener to capture them.");
Console.WriteLine("The color is determined by the severity level.\n");
// Disable the event listener - typically done when the application terminates
listener.DisableEvents(MyCompanyEventSource.Log);
listener.Dispose();
}
示例6: With2Listeners
public static void With2Listeners(EventSource logger, Action<ObservableEventListener, ObservableEventListener> scenario)
{
using (var listener1 = new ObservableEventListener())
using (var listener2 = new ObservableEventListener())
{
try
{
scenario(listener1, listener2);
}
finally
{
try
{ listener1.DisableEvents(logger); }
catch
{ }
try
{ listener2.DisableEvents(logger); }
catch
{ }
}
}
}
示例7: TestProfileAndExportDatabaseTable
//[Ignore("Depends on NorthWind database on local SQL Server.")]
public void TestProfileAndExportDatabaseTable() {
var listener = new ObservableEventListener();
listener.EnableEvents(TflEventSource.Log, EventLevel.Verbose);
var subscription = listener.LogToConsole(new LegacyLogFormatter());
var result = new Profiler().Profile("localhost.NorthWind.dbo.Customers");
new ProfileExporter().Export(result);
subscription.Dispose();
listener.DisableEvents(TflEventSource.Log);
listener.Dispose();
Assert.NotNull(result);
}
示例8: CanDisableEventsOnNonEnabledNonCreatedEventSource
public void CanDisableEventsOnNonEnabledNonCreatedEventSource()
{
var eventSourceName = "SensingEventSource";
using (EventListener listener = new ObservableEventListener())
{
listener.DisableEvents(eventSourceName);
Assert.IsFalse(SensingEventSource.Log.IsEnabled());
}
}
示例9: CanDisableEventsOnEnabledEventSourceBeforeItIsCreated
public void CanDisableEventsOnEnabledEventSourceBeforeItIsCreated()
{
var eventSourceName = "SensingEventSource";
using (EventListener listener = new ObservableEventListener())
{
listener.EnableEvents(eventSourceName, EventLevel.Error, EventKeywords.AuditSuccess | EventKeywords.AuditFailure);
listener.EnableEvents(eventSourceName, EventLevel.Informational, EventKeywords.Sqm, new Dictionary<string, string> { { "key1", "value1" } });
listener.EnableEvents(eventSourceName, EventLevel.Warning, EventKeywords.EventLogClassic, new Dictionary<string, string> { { "key2", "value2" } });
listener.DisableEvents(eventSourceName);
Assert.IsFalse(SensingEventSource.Log.IsEnabled());
Assert.AreEqual(0, SensingEventSource.Log.Commands.Count);
}
}
示例10: CanDeferRequestsForMultipleSources
public void CanDeferRequestsForMultipleSources()
{
using (EventListener listener = new ObservableEventListener())
{
listener.EnableEvents("DeferredEventSource1", EventLevel.Error, EventKeywords.AuditSuccess | EventKeywords.AuditFailure);
listener.EnableEvents("DeferredEventSource2", EventLevel.Informational, EventKeywords.Sqm, new Dictionary<string, string> { { "key1", "value1" } });
listener.EnableEvents("DeferredEventSource3", EventLevel.Warning, EventKeywords.EventLogClassic, new Dictionary<string, string> { { "key2", "value2" } });
listener.EnableEvents("DeferredEventSource2", EventLevel.Warning, EventKeywords.EventLogClassic, new Dictionary<string, string> { { "key2", "value2" } });
listener.EnableEvents("DeferredEventSource1", EventLevel.Warning, EventKeywords.EventLogClassic, new Dictionary<string, string> { { "key2", "value2" } });
listener.EnableEvents("DeferredEventSource1", EventLevel.Informational, EventKeywords.Sqm, new Dictionary<string, string> { { "key1", "value1" } });
listener.DisableEvents("DeferredEventSource2");
listener.EnableEvents("DeferredEventSource2", EventLevel.Error, EventKeywords.AuditSuccess | EventKeywords.AuditFailure);
listener.DisableEvents("DeferredEventSource3");
Assert.IsTrue(DeferredEventSource1.Log.IsEnabled(EventLevel.Informational, EventKeywords.Sqm));
Assert.IsFalse(DeferredEventSource1.Log.IsEnabled(EventLevel.Verbose, EventKeywords.Sqm));
Assert.IsTrue(DeferredEventSource2.Log.IsEnabled(EventLevel.Error, EventKeywords.AuditSuccess));
Assert.IsFalse(DeferredEventSource2.Log.IsEnabled(EventLevel.Warning, EventKeywords.AuditSuccess));
Assert.IsFalse(DeferredEventSource3.Log.IsEnabled());
}
}
示例11: MultipleEventListenersKeywords
static void MultipleEventListenersKeywords()
{
var listener1 = new ObservableEventListener();
var listener2 = new ObservableEventListener();
listener1.EnableEvents(MyCompanyEventSource.Log, EventLevel.LogAlways, MyCompanyEventSource.Keywords.Perf | MyCompanyEventSource.Keywords.Diagnostic);
listener2.EnableEvents(MyCompanyEventSource.Log, EventLevel.LogAlways, Keywords.All);
// Set up and enable the event listeners - typically done when the application starts
listener1.LogToConsole();
// The SinkSubscription is used later to flush the buffer
var subscription = listener2.LogToSqlDatabase("Demo Semantic Logging Instance", connectionString);
// Log some messages
MyCompanyEventSource.Log.PageStart(23, "http://mysite/demopage");
MyCompanyEventSource.Log.Startup();
MyCompanyEventSource.Log.Failure("Couldn't connect to server.");
Console.WriteLine("Written three log messages.\nUsing a basic console listener and a SQL listener to capture them.");
Console.WriteLine("Only the messages with the Perf or Diagnostic keywords appears in the console, \nall three appear in the SQL Database:\n");
// Disable the event listener - typically done when the application terminates
listener1.DisableEvents(MyCompanyEventSource.Log);
listener2.DisableEvents(MyCompanyEventSource.Log);
// Manually flush the buffer so you can see what's in the database
subscription.Sink.FlushAsync().Wait();
ShowContentsOfSqlDatabaseTable();
listener1.Dispose();
listener2.Dispose();
}
示例12: MultipleEventListenersLevel
static void MultipleEventListenersLevel()
{
// Set up and enable the event listeners - typically done when the application starts
var listener1 = new ObservableEventListener();
var listener2 = new ObservableEventListener();
listener1.EnableEvents(MyCompanyEventSource.Log, EventLevel.Error, Keywords.All);
listener2.EnableEvents(MyCompanyEventSource.Log, EventLevel.LogAlways, Keywords.All);
listener1.LogToConsole();
var subscription = listener2.LogToFlatFile(@"C:\Temp\DemoSemanticLogging.log", new EventTextFormatter("===================", "==================="));
// Log some messages
MyCompanyEventSource.Log.Startup();
MyCompanyEventSource.Log.Failure("Couldn't connect to server.");
Console.WriteLine("Written two log messages.\nUsing a basic console listener and a Flat File listener to capture them.");
Console.WriteLine("Only the critical message appears in the console, both appear in: \nC:\\Temp\\DemoSemanticLogging.log.\n");
// Flush the sink
subscription.Sink.FlushAsync().Wait();
// Disable the event listener - typically done when the application terminates
listener1.DisableEvents(MyCompanyEventSource.Log);
listener2.DisableEvents(MyCompanyEventSource.Log);
listener1.Dispose();
listener2.Dispose();
}
示例13: SimpleEventSourceWithColorMapper
static void SimpleEventSourceWithColorMapper()
{
// Set up and enable the event listener - typically done when the application starts
var listener = new ObservableEventListener();
listener.LogToConsole(new JsonEventTextFormatter(EventTextFormatting.Indented), new MyCustomColorMapper());
listener.EnableEvents(MyCompanyEventSource.Log, EventLevel.LogAlways, Keywords.All);
// Log some messages
MyCompanyEventSource.Log.Startup();
MyCompanyEventSource.Log.PageStop(99);
Console.WriteLine("Written two log messages.\nUsing a console listener with a JSON formatter to capture them.");
// Disable the event listener - typically done when the application terminates
listener.DisableEvents(MyCompanyEventSource.Log);
listener.Dispose();
}
示例14: SimpleEventSourceWithXMLFormatter
static void SimpleEventSourceWithXMLFormatter()
{
// Set up and enable the event listener - typically done when the application starts
var listener = new ObservableEventListener();
listener.LogToConsole(new XmlEventTextFormatter(EventTextFormatting.Indented));
listener.EnableEvents(MyCompanyEventSource.Log, EventLevel.LogAlways, Keywords.All);
// Log some messages
MyCompanyEventSource.Log.Startup();
MyCompanyEventSource.Log.Failure("Couldn't connect to server.");
Console.WriteLine("Written two log messages.\nUsing a console listener with an XML formatter to capture them.");
// Disable the event listener - typically done when the application terminates
listener.DisableEvents(MyCompanyEventSource.Log);
listener.Dispose();
}
示例15: EventWithPayloadAndEnumsInXml
public void EventWithPayloadAndEnumsInXml()
{
string fileName = "LogUsingPayloadWithEnumsInProc";
File.Delete(fileName);
var formatter = new XmlEventTextFormatter(EventTextFormatting.Indented, "d");
var logger = MockEventSourceInProcEnum.Logger;
using (var listener = new ObservableEventListener())
{
listener.EnableEvents(logger, EventLevel.LogAlways, Keywords.All);
listener.LogToFlatFile(fileName, formatter);
try
{
logger.SendEnumsEvent16(MockEventSourceInProcEnum.MyColor.Green, MockEventSourceInProcEnum.MyFlags.Flag1);
}
finally
{
listener.DisableEvents(logger);
}
}
var rawOutput = FlatFileHelper.GetAllText(fileName);
var entries = XDocument.Parse("<Events>" + rawOutput + "</Events>").Root.Elements();
Assert.AreEqual(1, entries.Count());
XmlFormattedEntry.Fill(entries.First());
Assert.AreEqual("a", XmlFormattedEntry.Payload.Elements().First().Attribute("Name").Value);
Assert.AreEqual("2", XmlFormattedEntry.Payload.Elements().First().Value);
Assert.AreEqual("b", XmlFormattedEntry.Payload.Elements().Last().Attribute("Name").Value);
Assert.AreEqual("1", XmlFormattedEntry.Payload.Elements().Last().Value);
}