Azure / diagnostics-eventflow

Microsoft Diagnostics EventFlow
MIT License
305 stars 97 forks source link

CsvHealthReporter does not output any logs #421

Open mskidavid opened 1 year ago

mskidavid commented 1 year ago

We're seeing some missing data in the sink, and wanted to check if there are any errors being logged by Event Flow. I'm having trouble getting the CsvHealthReporter to write errors to a CSV file. The output CSV file does not even get created and I wanted to know how to proceed with debugging this scenario?

We're on .NET6, here's the example setup code we're using:

serviceCollection.AddOptions<CsvHealthReporterConfiguration>()
    .Configure<IConfiguration>((csvHealthReporterConfiguration, configuration) =>
    {
        configuration.GetSection("EventFlow").GetSection("HealthReporter").Bind(csvHealthReporterConfiguration);
    });

serviceCollection.AddSingleton<IHealthReporter>(
    sp => new CsvHealthReporter(
        sp.GetRequiredService<IOptions<CsvHealthReporterConfiguration>>().Value));

serviceCollection.AddSingleton<IGenevaUploader, AppServiceGenevaLogUploader>();
serviceCollection.AddSingleton<IMetricsLogger, GenevaMetricsLogger>();

// Create event flow
serviceCollection.AddSingleton<ITelemetryProcessorFactory>(sp =>
{
    var genevaUploader = sp.GetRequiredService<IGenevaUploader>();
    var healthReporter = sp.GetRequiredService<IHealthReporter>();
    var inputs = new IObservable<EventData>[] 
    { 
        new ApplicationInsightsInputFactory().CreateItem(null, healthReporter) 
    };
    var sinks = new[] { new EventSink(new GenevaOutputEventFlow(healthReporter, genevaUploader), null) };
    DiagnosticPipeline eventFlow = new DiagnosticPipeline(healthReporter, inputs, null, sinks);
    return new EventFlowTelemetryProcessorFactory(eventFlow);
});
xiaomi7732 commented 1 year ago

Hey @mskidavid, what does the CsvHealthReporterConfiguration look like? Specifically, is there logFileFolder specified? And do you know does the app has permission to write to that folder?

That is interesting because according to this:

CsvHealthReporter will try to open the log file for writing during initialization. If it can't, by default, a debug message will be output to the debugger viewer like Visual Studio Output window, etc. This can happen especially if a value for the log file path is not provided (default is used, which is the application executables folder) and the application executables are residing on a read-only file system. Docker tools for Visual Studio use this configuration during debugging, so for containerized services the recommended practice is to specify the log file path explicitly.