Ejemplo n.º 1
0
        private static void Main(string[] args)
        {
            DiagnosticServer.Start();

            var logging = new LoggerFactory();

            logging.AddEventSourceLogger();

            var logger = logging.CreateLogger <Program>();

            Console.WriteLine($"Process ID: {Process.GetCurrentProcess().Id}");
            Console.WriteLine("Ready to start emitting events.");
            Console.WriteLine("Press X to quit.");
            Console.WriteLine("Press A to allocate 100 MB.");
            Console.WriteLine("Press G to force a GC.");
            Console.WriteLine("Press T to spawn parallel tasks.");
            Console.WriteLine("Press L to log a Microsoft.Extensions.Logging message to 'SampleMonitoredApp.Program'.");
            Console.WriteLine("Press E to write a random value to an EventSource/EventCounter.");

            while (true)
            {
                var key = Console.ReadKey(intercept: true);

                switch (key.Key)
                {
                case ConsoleKey.X:
                    return;

                case ConsoleKey.A:
                    AllocateMemory();
                    break;

                case ConsoleKey.G:
                    GC.Collect();
                    Console.WriteLine($"Total Memory after collection: {FormatSize(GC.GetTotalMemory(forceFullCollection: false))}");
                    break;

                case ConsoleKey.T:
                    SpawnTasks();
                    break;

                case ConsoleKey.L:
                    logger.Log(LogLevel.Information, new EventId(42, "SampleEvent"), "This is a sample event with an argument: {rando}", _rando.Next(0, 100));
                    break;

                case ConsoleKey.E:
                    SampleEventSource.Log.MyEvent(_rando.Next(0, 100));
                    break;
                }
            }
        }
Ejemplo n.º 2
0
        private static async Task Main(string[] args)
        {
            await DiagnosticServer.StartAsync();

            Console.WriteLine($"Process ID: {Process.GetCurrentProcess().Id}");
            Console.WriteLine("Ready to start emitting events. Press ENTER to emit an event, press Ctrl-C to shut down.");

            while (true)
            {
                Console.ReadLine();

                // Emit an event
                EmitEvent();
            }
        }
Ejemplo n.º 3
0
 public static void Main(string[] args)
 {
     DiagnosticServer.Start();
     Console.WriteLine($"Process ID: {Process.GetCurrentProcess().Id}");
     CreateWebHostBuilder(args).Build().Run();
 }