Example #1
0
    static async Task AsyncMain()
    {
        #region ConfigureLogging

        using (var listener = new CustomEventListener())
            using (var eventSourceLogger = new SimpleSourceLogger())
            {
                listener.EnableEvents(eventSourceLogger, EventLevel.Informational);
                var loggingFactory = LogManager.Use <EventSourceLoggingFactory>();
                loggingFactory.WithLogger(eventSourceLogger);

                var endpointConfiguration = new EndpointConfiguration("EndpointName");
                // other Endpoint Configuration

                var endpointInstance = await Endpoint.Start(endpointConfiguration)
                                       .ConfigureAwait(false);

                try
                {
                    // either a blocking action or split the instantiation
                    // and disposal in to the server startup and shutdown
                }
                finally
                {
                    await endpointInstance.Stop()
                    .ConfigureAwait(false);
                }
            }

        #endregion
    }
Example #2
0
    static async Task AsyncMain()
    {
        Console.Title = "Samples.Logging.SimpleSourceLogger";

        #region ConfigureLogging

        using (var listener = new CustomEventListener())
            using (var eventSourceLogger = new SimpleSourceLogger())
            {
                listener.EnableEvents(eventSourceLogger, EventLevel.Informational);
                var loggingFactory = LogManager.Use <EventSourceLoggingFactory>();
                loggingFactory.WithLogger(eventSourceLogger);

                var endpointConfiguration = new EndpointConfiguration("Samples.Logging.SimpleSourceLogger");
                ApplyBasicConfig(endpointConfiguration);

                var endpointInstance = await Endpoint.Start(endpointConfiguration)
                                       .ConfigureAwait(false);
                await SendMessage(endpointInstance)
                .ConfigureAwait(false);

                Console.WriteLine("Press any key to exit");
                Console.ReadKey();
                await endpointInstance.Stop()
                .ConfigureAwait(false);
            }

        #endregion
    }
Example #3
0
        public void LogMessage_CreatesProperEvents(EventLevel eventLevel, LogLevel logLevel, EventSourcesEventIds eventId)
        {
            CustomEventListener listener = new CustomEventListener();

            listener.EnableEvents(OmexLogEventSource.Instance, eventLevel);

            string   message  = "Test message";
            string   category = "Test category";
            int      tagId    = 0xFFF9;
            Activity activity = new Activity("Test activity");

            activity.Start().Stop();             // start and stop activity to get correlation id

            OmexLogEventSender logsSender = new OmexLogEventSender(
                OmexLogEventSource.Instance,
                new BasicMachineInformation(),
                new EmptyServiceContext(),
                Options.Create(new OmexLoggingOptions()));

            logsSender.LogMessage(activity, category, logLevel, tagId, 0, message);

            EventWrittenEventArgs eventInfo = listener.EventsInformation.Single(e => e.EventId == (int)eventId);

            AssertPayload(eventInfo, "message", message);
            AssertPayload(eventInfo, "category", category);
            AssertPayload(eventInfo, "activityId", activity.Id);
            AssertPayload(eventInfo, "tagId", "fff9");
        }
Example #4
0
        public void BuildStatelessService_LogsExceptions()
        {
            string serviceType           = "StatelessFailedServiceName";
            CustomEventListener listener = new CustomEventListener();

            listener.EnableEvents(ServiceInitializationEventSource.Instance, EventLevel.Error);

            Assert.ThrowsException <AggregateException>(() => new HostBuilder()
                                                        .ConfigureServices(c => c.AddTransient <TypeThatShouldNotBeResolvable>())
                                                        .BuildStatelessService(serviceType, c => { }),
                                                        "BuildStatelessService should fail in case of unresolvable dependencies");

            bool hasErrorEvent = listener.EventsInformation.Any(e =>
                                                                serviceType == GetPayloadValue <string>(e, ServiceTypePayloadName) &&
                                                                e.EventId == (int)EventSourcesEventIds.GenericHostBuildFailed);

            Assert.IsTrue(hasErrorEvent, "BuildStatelessService error should be logged");
        }
Example #5
0
        public void LogTimedScopeEndEvent_CreatesEvent(EventSourcesEventIds eventId, bool isHealthCheck)
        {
            CustomEventListener listener = new CustomEventListener();

            listener.EnableEvents(TimedScopeEventSource.Instance, EventLevel.Informational);

            string name     = "TestName";
            string subType  = "TestSubType";
            string metaData = "TestmetaData";

            TimedScopeEventSender logEventSource = new TimedScopeEventSender(
                TimedScopeEventSource.Instance,
                new HostingEnvironment {
                ApplicationName = "TestApp"
            },
                new NullLogger <TimedScopeEventSender>());

            string   expectedActivityId = string.Empty;
            Activity activity           = new Activity(name);

            using (TimedScope scope = new TimedScope(activity, TimedScopeResult.Success).Start())
            {
                expectedActivityId = activity.Id;
                scope.SetSubType(subType);
                scope.SetMetadata(metaData);
                activity.SetUserHash("TestUserHash");
                if (isHealthCheck)
                {
                    activity.MarkAsHealthCheck();
                }
            }

            logEventSource.LogActivityStop(activity);

            EventWrittenEventArgs eventInfo = listener.EventsInformation.Single(e => e.EventId == (int)eventId);

            AssertPayload(eventInfo, "name", name);
            AssertPayload(eventInfo, "subType", subType);
            AssertPayload(eventInfo, "metadata", metaData);
            AssertPayload(eventInfo, "activityId", expectedActivityId);
        }
Example #6
0
        static async Task Main(string[] args)
        {
            var listener = new CustomEventListener();

            listener.EnableEvents(DefaultEventSource.Log, EventLevel.Warning);

            string storageConnectionString = Storage.StorageConnectionString;
            var    settings = new AzureStorageOrchestrationServiceSettings
            {
                StorageConnectionString = storageConnectionString,
                //TaskHubName = "PartitionTest",
                TaskHubName    = "PartitionTest",
                PartitionCount = 1,
                //MaxConcurrentTaskOrchestrationWorkItems = 100,
                //MaxConcurrentTaskActivityWorkItems = 10,
                //MaxStorageOperationConcurrency = Environment.ProcessorCount * 25,
            };

            var orchestrationServiceAndClient = new AzureStorageOrchestrationService(settings);
            //just for test
            await orchestrationServiceAndClient.DeleteAsync();

            //await Task.Delay(TimeSpan.FromSeconds(60));
            await orchestrationServiceAndClient.CreateIfNotExistsAsync();

            var taskHubClient = new TaskHubClient(orchestrationServiceAndClient);
            var taskHubWorker = new TaskHubWorker(orchestrationServiceAndClient);

            //1.create 1000** instance
            await Test.CreateMockOrchestrationInstancesAsync(40, 5, taskHubClient);

            //
            await Test.StartWorker(taskHubWorker);

            Console.WriteLine("Press any key to quit.");
            Console.ReadLine();
        }