Exemplo n.º 1
0
        private void btnStart_Clicked(object sender, RoutedEventArgs e)
        {
            CsvHealthReporterConfiguration configuration = new CsvHealthReporterConfiguration()
            {
                LogFileFolder  = tbLogFileFolder.Text.Trim(),
                LogFilePrefix  = tbLogFilePrefix.Text.Trim(),
                MinReportLevel = tbMinReportLevel.Text.Trim()
            };

            reporter = new CustomHealthReporter(configuration, this.manualTrigger);
            reporter.Activate();
            int intervalInMs;

            if (!int.TryParse(tbMessageInterval.Text, out intervalInMs))
            {
                intervalInMs = 500;
            }

            timer = new Timer(state =>
            {
                (state as CsvHealthReporter)?.ReportHealthy(DateTime.Now.ToString(CultureInfo.CurrentCulture.DateTimeFormat.SortableDateTimePattern), "HealthReporterBuster");
                hit++;
            }, reporter, 0, intervalInMs);

            hitReporter.Interval  = TimeSpan.FromMilliseconds(500);
            hitReporter.Tick     += HitReporter_Tick;
            hitReporter.IsEnabled = true;

            btnStart.IsEnabled  = false;
            btnStop.IsEnabled   = true;
            btnSwitch.IsEnabled = true;
        }
Exemplo n.º 2
0
        private static DiagnosticPipeline CreateEventFlow(string[] args)
        {
            // Create configuration instance to access configuration information for EventFlow pipeline
            // To learn about common configuration sources take a peek at https://github.com/aspnet/MetaPackages/blob/master/src/Microsoft.AspNetCore/WebHost.cs (CreateDefaultBuilder method).
            var configBuilder = new ConfigurationBuilder()
                                .AddEnvironmentVariables();

            var devEnvironmentVariable = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
            var isDevelopment          = string.IsNullOrEmpty(devEnvironmentVariable) ||
                                         devEnvironmentVariable.ToLower() == "development";

            if (isDevelopment)
            {
                configBuilder.AddUserSecrets <Program>();
            }
            else
            {
                configBuilder.SetBasePath(Directory.GetCurrentDirectory());
                configBuilder.AddJsonFile("appsettings.json", false, false);
            }

            if (args != null)
            {
                configBuilder.AddCommandLine(args);
            }
            var config = configBuilder.Build();

            // SEE https://github.com/Azure/diagnostics-eventflow#http
            var httpConfig     = config.GetSection("HttpEventSinkConfig");
            var filterConfig   = config.GetSection("FilterConfig");
            var pipelineConfig = new DiagnosticPipelineConfiguration()
            {
                MaxBatchDelayMsec             = 5000,  // Specifies the maximum time that events are held in a batch before the batch gets pushed through the pipeline to filters and outputs. The batch is pushed down when it reaches the maxEventBatchSize, or its oldest event has been in the batch for more than maxBatchDelayMsec milliseconds.
                PipelineCompletionTimeoutMsec = 10000, // Specifies the timeout to wait for the pipeline to shutdown and clean up. The shutdown process starts when the DiagnosePipeline object is disposed, which usually happens on application exit.
                MaxEventBatchSize             = 50,    // Specifies the maximum number of events to be batched before the batch gets pushed through the pipeline to filters and outputs. The batch is pushed down when it reaches the maxEventBatchSize, or its oldest event has been in the batch for more than maxBatchDelayMsec milliseconds.
                PipelineBufferSize            = 1000   // Specifies how many events the pipeline can buffer if the events cannot flow through the pipeline fast enough. This buffer protects loss of data in cases where there is a sudden burst of data.
            };
            var healthReporter = new CsvHealthReporter(new CsvHealthReporterConfiguration());
            var aiInput        = new ApplicationInsightsInputFactory().CreateItem(null, healthReporter);
            var aiFilters      = new CustomFilterFactory().CreateItem(filterConfig, healthReporter);
            var inputs         = new IObservable <EventData>[] { aiInput };
            var filters        = new IFilter[] { aiFilters };

            var sinks = new EventSink[]
            {
                new EventSink(new StdOutput(healthReporter), null),
                new EventSink(new HttpOutput(httpConfig, healthReporter), filters) // again, see https://github.com/Azure/diagnostics-eventflow#http
            };

            return(new DiagnosticPipeline(healthReporter, inputs, filters, sinks, pipelineConfig, disposeDependencies: true));
        }
Exemplo n.º 3
0
        private void btnStop_Clicked(object sender, RoutedEventArgs e)
        {
            if (timer != null)
            {
                timer.Dispose();
                timer = null;
            }

            if (reporter != null)
            {
                reporter.Dispose();
                reporter = null;
            }

            btnStart.IsEnabled  = true;
            btnStop.IsEnabled   = false;
            btnSwitch.IsEnabled = false;
        }
Exemplo n.º 4
0
        public static void Main(string[] args)
        {
            // HealthReporter
            var configBuilder = new ConfigurationBuilder();

            configBuilder.AddJsonFile("config.json");
            var configuration = configBuilder.Build();

            using (IHealthReporter reporter = new CsvHealthReporter("FileReportConfig.json"))
            {
                // Listeners
                List <IObservable <EventData> > inputs = new List <IObservable <EventData> >();
                inputs.Add((new TraceInputFactory()).CreateItem(configuration, reporter));

                // Senders
                var outputs = new List <IOutput>();
                outputs.Add(new StdOutput(reporter));

                DiagnosticPipeline pipeline = new DiagnosticPipeline(
                    reporter,
                    inputs,
                    null,
                    new EventSink[] { new EventSink(new StdOutput(reporter), null) });

                // Build up the pipeline
                Console.WriteLine("Pipeline is created.");

                // Send a trace to the pipeline
                Trace.TraceInformation("This is a message from trace . . .");
                Trace.TraceWarning("This is a warning from trace . . .");


                // Check the result
                Console.WriteLine("Press any key to continue . . .");
                Console.ReadKey(true);
            }
        }