当前位置: 首页>>代码示例>>C#>>正文


C# ObservableEventListener.Dispose方法代码示例

本文整理汇总了C#中ObservableEventListener.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# ObservableEventListener.Dispose方法的具体用法?C# ObservableEventListener.Dispose怎么用?C# ObservableEventListener.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ObservableEventListener的用法示例。


在下文中一共展示了ObservableEventListener.Dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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));
        }
开发者ID:modulexcite,项目名称:DataProfiler,代码行数:26,代码来源:Development.cs

示例2: Main

        static void Main(string[] args)
        {
            // optimizing IOCP performance
            int minWorkerThreads;
            int minCompletionPortThreads;
            ThreadPool.GetMinThreads(out minWorkerThreads, out minCompletionPortThreads);
            ThreadPool.SetMinThreads(minWorkerThreads, Math.Max(16, minCompletionPortThreads));

            int threadCount = Environment.ProcessorCount;
            if (args.Length > 0)
            {
                threadCount = int.Parse(args[0]);
            }

            var eventListener = new ObservableEventListener();
            eventListener.LogToConsole();
            eventListener.EnableEvents(BootstrapperEventSource.Log, EventLevel.Verbose);
            eventListener.EnableEvents(MqttIotHubAdapterEventSource.Log, EventLevel.Verbose);
            eventListener.EnableEvents(ChannelEventSource.Log, EventLevel.Verbose);
            eventListener.EnableEvents(BootstrapEventSource.Log, EventLevel.Verbose);
            eventListener.EnableEvents(ExecutorEventSource.Log, EventLevel.Verbose);
            eventListener.EnableEvents(MqttEventSource.Log, EventLevel.Verbose);

            try
            {
                var cts = new CancellationTokenSource();

                var certificate = new X509Certificate2("protocol-gateway.contoso.com.pfx", "password");
                var settingsProvider = new AppConfigSettingsProvider();
                BlobSessionStatePersistenceProvider blobSessionStateProvider = BlobSessionStatePersistenceProvider.CreateAsync(
                    settingsProvider.GetSetting("BlobSessionStatePersistenceProvider.StorageConnectionString"),
                    settingsProvider.GetSetting("BlobSessionStatePersistenceProvider.StorageContainerName")).Result;

                TableQos2StatePersistenceProvider tableQos2StateProvider = TableQos2StatePersistenceProvider.CreateAsync(
                    settingsProvider.GetSetting("TableQos2StatePersistenceProvider.StorageConnectionString"),
                    settingsProvider.GetSetting("TableQos2StatePersistenceProvider.StorageTableName")).Result;

                var bootstrapper = new Bootstrapper(settingsProvider, blobSessionStateProvider, tableQos2StateProvider);
                Task.Run(() => bootstrapper.RunAsync(certificate, threadCount, cts.Token), cts.Token);

                while (true)
                {
                    string input = Console.ReadLine();
                    if (input != null && input.ToLowerInvariant() == "exit")
                    {
                        break;
                    }
                }

                cts.Cancel();
                bootstrapper.CloseCompletion.Wait(TimeSpan.FromSeconds(20));
            }
            finally
            {
                eventListener.Dispose();
            }
        }
开发者ID:nberdy,项目名称:azure-iot-protocol-gateway,代码行数:57,代码来源:Program.cs

示例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();
        }
开发者ID:modulexcite,项目名称:DataProfiler,代码行数:14,代码来源:Program.cs

示例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();
    }
开发者ID:HondaBey,项目名称:EnterpriseLibrary6,代码行数:15,代码来源:Program.cs

示例5: RunClientAsync

        static async Task RunClientAsync()
        {
            var eventListener = new ObservableEventListener();
            eventListener.LogToConsole();
            eventListener.EnableEvents(DefaultEventSource.Log, EventLevel.Verbose);

            var group = new MultithreadEventLoopGroup();

            X509Certificate2 cert = null;
            string targetHost = null;
            if (EchoClientSettings.IsSsl)
            {
                cert = new X509Certificate2("dotnetty.com.pfx", "password");
                targetHost = cert.GetNameInfo(X509NameType.DnsName, false);
            }
            try
            {
                var bootstrap = new Bootstrap();
                bootstrap
                    .Group(group)
                    .Channel<TcpSocketChannel>()
                    .Option(ChannelOption.TcpNodelay, true)
                    .Handler(new ActionChannelInitializer<ISocketChannel>(channel =>
                    {
                        IChannelPipeline pipeline = channel.Pipeline;

                        if (cert != null)
                        {
                            pipeline.AddLast(new TlsHandler(stream => new SslStream(stream, true, (sender, certificate, chain, errors) => true), new ClientTlsSettings(targetHost)));
                        }
                        pipeline.AddLast(new LengthFieldPrepender(2));
                        pipeline.AddLast(new LengthFieldBasedFrameDecoder(ushort.MaxValue, 0, 2, 0, 2));

                        pipeline.AddLast(new EchoClientHandler());
                    }));

                IChannel bootstrapChannel = await bootstrap.ConnectAsync(new IPEndPoint(EchoClientSettings.Host, EchoClientSettings.Port));

                Console.ReadLine();

                await bootstrapChannel.CloseAsync();
            }
            finally
            {
                group.ShutdownGracefullyAsync().Wait(1000);
                eventListener.Dispose();
            }
        }
开发者ID:RabbitTeam,项目名称:DotNetty,代码行数:48,代码来源:Program.cs

示例6: RunServerAsync

        static async Task RunServerAsync()
        {
            var eventListener = new ObservableEventListener();
            eventListener.LogToConsole();
            eventListener.EnableEvents(DefaultEventSource.Log, EventLevel.Verbose);

            var bossGroup = new MultithreadEventLoopGroup(1);
            var workerGroup = new MultithreadEventLoopGroup();
            X509Certificate2 tlsCertificate = null;
            if (EchoServerSettings.IsSsl)
            {
                tlsCertificate = new X509Certificate2("dotnetty.com.pfx", "password");
            }
            try
            {
                var bootstrap = new ServerBootstrap();
                bootstrap
                    .Group(bossGroup, workerGroup)
                    .Channel<TcpServerSocketChannel>()
                    .Option(ChannelOption.SoBacklog, 100)
                    .Handler(new LoggingHandler(LogLevel.INFO))
                    .ChildHandler(new ActionChannelInitializer<ISocketChannel>(channel =>
                    {
                        IChannelPipeline pipeline = channel.Pipeline;
                        if (tlsCertificate != null)
                        {
                            pipeline.AddLast(TlsHandler.Server(tlsCertificate));
                        }
                        pipeline.AddLast(new LengthFieldPrepender(2));
                        pipeline.AddLast(new LengthFieldBasedFrameDecoder(ushort.MaxValue, 0, 2, 0, 2));

                        pipeline.AddLast(new EchoServerHandler());
                    }));

                IChannel bootstrapChannel = await bootstrap.BindAsync(EchoServerSettings.Port);

                Console.ReadLine();

                await bootstrapChannel.CloseAsync();
            }
            finally
            {
                Task.WaitAll(bossGroup.ShutdownGracefullyAsync(), workerGroup.ShutdownGracefullyAsync());
                eventListener.Dispose();
            }
        }
开发者ID:RabbitTeam,项目名称:DotNetty,代码行数:46,代码来源:Program.cs

示例7: 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();
     }
开发者ID:HondaBey,项目名称:EnterpriseLibrary6,代码行数:17,代码来源:Program.cs

示例8: TestUdpEventSink

        public async Task TestUdpEventSink()
        {
            int port = 11001;
            var udpclient = new UdpClient(port);

            var slabListener = new ObservableEventListener();
            slabListener.Subscribe(new UdpEventSink(IPAddress.Loopback, port, new TestEventFormatter()));
            var source = TestEventSource.GetInstance();
            slabListener.EnableEvents(source, EventLevel.LogAlways, Keywords.All);

            var t = udpclient.ReceiveAsync();

            source.Message("Boris", "Meep");

            var receivedText = Encoding.UTF8.GetString((await t).Buffer);

            Assert.Equal(
                "EventId=1 EventName=MessageInfo Level=Error \"FormattedMessage=Meep - Boris\" \"message=Boris\" \"caller=Meep\"\r\n",
                receivedText);

            udpclient.Close();
            slabListener.Dispose();
        }
开发者ID:JimSimpkins13,项目名称:splunk-library-dotnetlogging,代码行数:23,代码来源:TestUdp.cs

示例9: Main

        static void Main(string[] args)
        {
            var listener = new ObservableEventListener();
            listener.EnableEvents(RxFloodQuickStartEventSource.Log, EventLevel.LogAlways, Keywords.All);

            // ThrottleEventsWithEventId is a custom extension method that shows how you can leverage the power of Reactive Extensions (Rx) 
            // to perform filtering (or transformation) of the event stream before it is sent to the underlying sink.
            // In this case, ThrottleEventsWithEventId will throttle entries with EventID=4 and mute additional occurrences for 15 seconds.
            // This prevents a particular event from flooding the log sink, making it difficult to diagnose other issues.
            // This can be useful in the case that a high-throughput event does not have a keyword or verbosity setting that makes it easy
            // to exclude it in the call to listener.EnableEvents(EventSource, EventLevel, EventKeywords).

            // Note: For basic scenarios without this extra filtering, you DO NOT need to use Rx, and SLAB does not depend on it.

            var subscription = listener
                                .ThrottleEventsWithEventId(TimeSpan.FromSeconds(15), ThrottledEventId)
                                .LogToConsole(SingleLineFormatter);

            // The previous custom extension method (ThrottleEventsWithEventId) is all that is needed to call to throttle
            // an event that is flooding the log. 
            // The rest of the code in this QuickStart is here to show an interactive demo of how it looks if this filter is turned on or off.
            bool currentlyThrottling = true;

            var cts = new CancellationTokenSource();

            Console.WriteLine("This program simulates the scenario of a particular event being logged multiple times in succession when a certain condition occurs,");
            Console.WriteLine("such as when there is a transient or expected connectivity error during system upgrades.");
            Console.WriteLine();
            Console.WriteLine("While the application is logging messages, use the following commands:");
            Console.WriteLine(" [ESC]      Exists the application.");
            Console.WriteLine(" [Spacebar] Toggles the throttling filter.");
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("Press any key to start doing background work.");

            var key = Console.ReadKey(false);
            if (key.Key == ConsoleKey.Escape)
            {
                return;
            }

            DoBackgroundWork(cts.Token);

            while (!cts.IsCancellationRequested)
            {
                key = Console.ReadKey(false);
                switch (key.Key)
                {
                    case ConsoleKey.Spacebar:
                        subscription.Dispose();
                        if (currentlyThrottling)
                        {
                            Console.WriteLine("Filter toggled: event entries will not be throttled. In this scenario, if there is no post-filtering of events, important messages could go unnoticed.");
                            Thread.Sleep(TimeSpan.FromSeconds(3));
                            currentlyThrottling = false;

                            // Note that the events are sent directly to the console, without using Reactive Extensions.
                            subscription = listener
                                                .LogToConsole(SingleLineFormatter);
                        }
                        else
                        {
                            Console.WriteLine("Filter toggled: event entries with ID {0} will be throttled for 15 seconds to prevent that type of entry to flood the log.", ThrottledEventId);
                            Thread.Sleep(TimeSpan.FromSeconds(3));
                            currentlyThrottling = true;

                            // Note that the events are filtered first and then sent to the console, using Reactive Extensions.
                            subscription = listener
                                                .ThrottleEventsWithEventId(TimeSpan.FromSeconds(15), ThrottledEventId)
                                                .LogToConsole(SingleLineFormatter);
                        }
                        
                        break;

                    case ConsoleKey.Escape:
                        cts.Cancel();
                        break;
                }
            }

            listener.Dispose();
        }
开发者ID:guyzo,项目名称:semantic-logging,代码行数:82,代码来源:Program.cs

示例10: 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);
        }
开发者ID:modulexcite,项目名称:DataProfiler,代码行数:16,代码来源:Development.cs

示例11: UsingRxFiltering

    static void UsingRxFiltering()
    {
      // Configure the observable listener.
      var listener = new ObservableEventListener();
      listener.EnableEvents(MyCompanyEventSource.Log, EventLevel.LogAlways, Keywords.All);

      // Use the custom filter extension method (see the ObservableHelper class).
      // If an message of level Error is received, send it and the two previous
      // information messages to the console.
      listener
        .FlushOnTrigger(entry => entry.Schema.Level <= EventLevel.Error, bufferSize: 2)
        .LogToConsole();

      Console.WriteLine("Sending 20 informational messages and one error message.");
      for (int i = 0; i < 20; i++)
      {
        MyCompanyEventSource.Log.DBQueryStart("select... (query #" + i);
      }
      MyCompanyEventSource.Log.DBQueryError(231);
      Console.WriteLine("Only the last two information messages and the error message get sent to the console sink.");

      listener.Dispose();
    }
开发者ID:HondaBey,项目名称:EnterpriseLibrary6,代码行数:23,代码来源:Program.cs

示例12: 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();
    }
开发者ID:HondaBey,项目名称:EnterpriseLibrary6,代码行数:29,代码来源:Program.cs

示例13: 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();
    }
开发者ID:HondaBey,项目名称:EnterpriseLibrary6,代码行数:27,代码来源:Program.cs

示例14: 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();
    }
开发者ID:HondaBey,项目名称:EnterpriseLibrary6,代码行数:16,代码来源:Program.cs

示例15: 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();
    }
开发者ID:HondaBey,项目名称:EnterpriseLibrary6,代码行数:16,代码来源:Program.cs


注:本文中的ObservableEventListener.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。