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 }
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 }
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"); }
public static void Run() { var listener = new CustomEventListener(); listener.WriteEvent += Listener_WriteEvent; new Thread(Working).Start(); }
public MainWindow() { InitializeComponent(); textHandler = new TextHandler(ResultText); register = new RegisterClass(); diagnose = new DiagnoseClass(); registerEventManager = new CustomEventManager(); registerListener = new CustomEventListener(register, textHandler.Text); registerEventManager.Handler += registerListener.Execute; diagnoseEventManager = new CustomEventManager(); diagnoseListener = new CustomEventListener(diagnose, textHandler.Text); diagnoseEventManager.Handler += diagnoseListener.Execute; }
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"); }
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); }
public static void Test() { var eventSource = new CustomEventSource(); var listener = new CustomEventListener(); //add handler listener.HandleEvent to CustomEvent of CustomEventSource WeakEventManager <CustomEventSource, CustomEventArg> .AddHandler(eventSource, "CustomEvent", listener.HandleEvent); //trigger event and listener.HandleEvent will be executed eventSource.Raise("First message"); //set listener to null listener = null; //trigger gc and the listener object will be collected. GCUtils.TriggerGC(); //trigger event and listener.HandleEvent stil will NOT be executed eventSource.Raise("Second Message"); Console.Read(); }
public static void Test() { var eventSource = new CustomEventSource(); var listener = new CustomEventListener(); //register event listener eventSource.CustomEvent += listener.HandleEvent; //trigger event and listener.HandleEvent will be executed eventSource.Raise("First Message from CustomEventSource"); //set listener to null listener = null; //trigger gc but the listener object will NOT collected. GCUtils.TriggerGC(); //trigger event and listener.HandleEvent stil will be executed eventSource.Raise("Second Message from CustomEventSource"); Console.Read(); }
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(); }