Skip to content

[Bug] Log file is not properly recorded when exception thrown #10946

@filzrev

Description

@filzrev

Describe the bug
docfx record logs at following lines.

public static int Run(LogOptions options, Action run)
{
SetupLogger(options);
run();
CleanupLogger();
return Logger.HasError ? -1 : 0;
}

But when exception thrown.
Cleanup is not called. and when using --log option. log is not properly because ReportLogListener using StreamWriter and need Flush before exit.

Additionally, Exception information seems be outputted to console only. and it's not recorded to log file.

static void OnException(Exception e, ITypeResolver? resolver)
{
if (e is CommandAppException cae)
{
if (cae.Pretty is { } pretty)
AnsiConsole.Write(pretty);
else
AnsiConsole.MarkupInterpolated($"[red]Error:[/] {e.Message}");
}
else
{
AnsiConsole.WriteException(e, new ExceptionSettings()
{
Format = ExceptionFormats.ShortenEverything,
Style = new()
{
ParameterName = Color.Grey,
ParameterType = Color.Grey78,
LineNumber = Color.Grey78,
},
});
}
}

Expected behavior

  • All logs are recorded to log file.
  • thrown exception information is included.

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