Skip to content

MetroLog stops logging when a few exceptions occurred #103

@basprins

Description

@basprins

I have a universal app that runs on a Raspberry Pi with Windows IoT which uses MetroLog as loggings framework.

For some completely unknown reasons to me, sometimes MetroLog decides to stop logging to file completely. My app still runs, and it responds and does what it should do, except that there are no new log entries (and I know for certain that code is executes with log statements).

The usage of MetroLog in my app is as follows:

Creation/initialization in my App.xaml.cs

    private static readonly ILogger Log;

    static App()
    {
        var streamingFileTarget = new StreamingFileTarget(new SingleLineLayout());
        streamingFileTarget.FileNamingParameters.CreationMode = FileCreationMode.AppendIfExisting;
        streamingFileTarget.KeepLogFilesOpenForWrite = false;
        streamingFileTarget.RetainDays = 90;

        LogManagerFactory.DefaultConfiguration.AddTarget(LogLevel.Trace, LogLevel.Fatal, streamingFileTarget);

        Log = LogManagerFactory.DefaultLogManager.GetLogger<App>();
    }

For the rest, I have a lot of classes that have a static Logger instance, like this:

    private static ILogger Log = LogManagerFactory.DefaultLogManager.GetLogger(typeof(FlowSensor));

or:

    private static readonly ILogger Log = LogManagerFactory.DefaultLogManager.GetLogger<CloudClient>();

and usage of these instances is straight forward like this:

            try
            {
               // do stuff
            }
            catch (Exception e)
            {
                Log.Error($"'{nameof(GetEntityAsync)}' ran into an exception (retry counter = {i}): {e}");

                if (i == MaxRetries)
                {
                    throw;
                }

                await Task.Delay(30);
            }

The example above causes the logger to stop completely, it retries a couple of times, and I can see the log messages in the logging, and then nothing else gets logged.

Any idea how to troubleshoot this? I really have no clue whatsoever what is the cause of this weird behaviour.

Again. the App continues to run, and 100% sure code gets executes that contains log statements, so it seems that the logger died / stops flushing to disk?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions