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


C# ObservableEventListener.Subscribe方法代码示例

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


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

示例1: TestEventSink

        public async Task TestEventSink()
        {
            var listener = new TcpListener(IPAddress.Loopback, 0);
            listener.Start();
            int port = ((IPEndPoint)listener.Server.LocalEndPoint).Port;

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

            var listenerClient = await listener.AcceptTcpClientAsync();

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

            var receiverReader = new StreamReader(listenerClient.GetStream());
            var line = await receiverReader.ReadLineAsync();

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

            listenerClient.Close();
            listener.Stop();
            slabListener.Dispose();
        }
开发者ID:JimSimpkins13,项目名称:splunk-library-dotnetlogging,代码行数:28,代码来源:TestTcp.cs

示例2: UnderReleaseBufferLeak

        public void UnderReleaseBufferLeak()
        {
            ResourceLeakDetector.DetectionLevel preservedLevel = ResourceLeakDetector.Level;
            try
            {
                ResourceLeakDetector.Level = ResourceLeakDetector.DetectionLevel.Paranoid;
                var eventListener = new ObservableEventListener();
                Mock<IObserver<EventEntry>> logListener = this.mockRepo.Create<IObserver<EventEntry>>();
                var eventTextFormatter = new EventTextFormatter();
                Func<EventEntry, bool> leakPredicate = y => y.TryFormatAsString(eventTextFormatter).Contains("LEAK");
                logListener.Setup(x => x.OnNext(It.Is<EventEntry>(y => leakPredicate(y)))).Verifiable();
                logListener.Setup(x => x.OnNext(It.Is<EventEntry>(y => !leakPredicate(y))));
                eventListener.Subscribe(logListener.Object);
                eventListener.EnableEvents(DefaultEventSource.Log, EventLevel.Verbose);

                this.CreateAndForgetBuffer();

                GC.Collect();
                GC.WaitForPendingFinalizers();

                this.mockRepo.Verify();
            }
            finally
            {
                ResourceLeakDetector.Level = preservedLevel;
            }
        }
开发者ID:RabbitTeam,项目名称:DotNetty,代码行数:27,代码来源:LeakDetectionTest.cs

示例3: Leak

        public void Leak()
        {
            var eventListener = new ObservableEventListener();
            Mock<IObserver<EventEntry>> logListener = this.mockRepo.Create<IObserver<EventEntry>>();
            var eventTextFormatter = new EventTextFormatter();
            Func<EventEntry, bool> leakPredicate = y => y.TryFormatAsString(eventTextFormatter).Contains("LEAK");
            logListener.Setup(x => x.OnNext(It.Is<EventEntry>(y => leakPredicate(y)))).Verifiable();
            logListener.Setup(x => x.OnNext(It.Is<EventEntry>(y => !leakPredicate(y))));
            eventListener.Subscribe(logListener.Object);
            eventListener.EnableEvents(DefaultEventSource.Log, EventLevel.Verbose);

            var bufPool = new PooledByteBufferAllocator(100, 1000);
            IByteBuffer buffer = bufPool.Buffer(10);

            buffer = null;

            GC.Collect();
            GC.WaitForPendingFinalizers();

            this.mockRepo.Verify();
        }
开发者ID:l1183479157,项目名称:DotNetty,代码行数:21,代码来源:LeakDetectionTest.cs

示例4: 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

示例5: EnableNonTransientErrorsHandling

        private void EnableNonTransientErrorsHandling()
        {
            var observable = new ObservableEventListener();
            this.slabNonTransientErrors = observable;

            if (this.consoleMode)
            {
                observable.LogToConsole();
            }
            else
            {
                observable.Subscribe(new ServiceEventLogSink(this.EventLog));
            }

            EventLevel level;
            if (!Enum.TryParse(ConfigurationManager.AppSettings[NonTransientErrorsEventLevelKey], out level))
            {
                level = EventLevel.LogAlways;
            }

            this.slabNonTransientErrors.EnableEvents(SemanticLoggingEventSource.Log, level, Keywords.All);

            // Capture any unhandled error in worker threads
            AppDomain.CurrentDomain.UnhandledException += this.OnAppDomainUnhandledException;

            // Handle unobserved task exceptions
            TaskScheduler.UnobservedTaskException += this.OnUnobservedTaskException;
        }
开发者ID:EdHastings,项目名称:semantic-logging,代码行数:28,代码来源:TraceEventServiceHost.cs

示例6: InitializeLocalLogging

        protected override void InitializeLocalLogging()
        {
            _platformEventStream = new ObservableEventListener();
            _platformEventStream.EnableEvents(EventSources.PlatformSources, TraceLevel);

            var formatter = new EventTextFormatter(dateTimeFormat: "O");
            _platformEventStream.Subscribe(evt =>
            {
                StringBuilder b = new StringBuilder();
                using (var writer = new StringWriter(b))
                {
                    formatter.WriteEvent(evt, writer);
                }
                Trace.WriteLine(b.ToString());
            });

            try
            {
                var logsResource = RoleEnvironment.GetLocalResource("Logs");

                var logFile = Path.Combine(logsResource.RootPath, "Platform", "Platform.log.json");

                // Initialize core platform logging
                _subscriptions.Add(_platformEventStream.LogToRollingFlatFile(
                    fileName: logFile,
                    rollSizeKB: 1024,
                    timestampPattern: "yyyyMMdd-HHmmss",
                    rollFileExistsBehavior: RollFileExistsBehavior.Increment,
                    rollInterval: RollInterval.Hour,
                    formatter: new JsonEventTextFormatter(EventTextFormatting.Indented, dateTimeFormat: "O"),
                    maxArchivedFiles: 768, // We have a buffer size of 1024MB for this folder
                    isAsync: false));
            }
            catch (Exception ex)
            {
                ServicePlatformEventSource.Log.FatalException(ex);
                throw;
            }
        }
开发者ID:stephenosrajan,项目名称:NuGet.Services.Platform,代码行数:39,代码来源:AzureServiceHost.cs

示例7: TraceSource

        private SinkTrace TraceSource(
            RequestHandler handler,
            HttpEventCollectorEventInfo.Metadata metadata = null,
            HttpEventCollectorSender.SendMode sendMode = HttpEventCollectorSender.SendMode.Parallel,
            int batchInterval = 0,
            int batchSizeBytes = 0,
            int batchSizeCount = 0,
            HttpEventCollectorSender.HttpEventCollectorMiddleware middleware = null)
        {
            var listener = new ObservableEventListener();
            var sink = new HttpEventCollectorSink(
                 uri: uri,
                 token: token,
                 formatter: new TestEventFormatter(),
                 metadata: metadata,
                 sendMode: sendMode,
                 batchInterval: batchInterval,
                 batchSizeBytes: batchSizeBytes,
                 batchSizeCount: batchSizeCount,
                 middleware: MiddlewareInterceptor(handler, middleware));
            listener.Subscribe(sink);

            var eventSource = TestEventSource.GetInstance();
            listener.EnableEvents(eventSource, EventLevel.LogAlways, Keywords.All);
            return new SinkTrace() {
                Source = eventSource,
                Sink = sink,
                Listener = listener
            };
        }
开发者ID:JimSimpkins13,项目名称:splunk-library-dotnetlogging,代码行数:30,代码来源:TestHttpEventCollector.cs

示例8: SetUp

        public void SetUp()
        {
            _clientMock.Setup(x => x.GetDatabase(InstanceName, null)).Returns(() => _databaseMock.Object);
            _databaseMock.Setup(x => x.GetCollection<BsonDocument>(CollectionName, null))
                .Returns(() => _collectionMock.Object);

            _sink = new MongoSink(
                _clientMock.Object,
                InstanceName,
                CollectionName,
                _bufferingInterval,
                int.MaxValue,
                int.MaxValue,
                TimeSpan.Zero);

            _eventListener = new ObservableEventListener();
            _eventListener.EnableEvents(TestEventSource.EventSource, EventLevel.LogAlways);
            _subscription = _eventListener.Subscribe(_sink);
        }
开发者ID:TIMEmSYSTEM,项目名称:slab-mongodb,代码行数:19,代码来源:MongoSinkBufferingIntervalTests.cs


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