Logging errors (C#)

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Tanders

Hey all;

I’ve tried to log errors, so I can figure out the error which closed the program. My current setup is as follows:

Project Settings → Logging → Enable File logging: True
Project Settings → Logging → Enable File logging.pc: True
Logpath: output/output.log (I create this folder on run)
Max Log Files:5

It logs fine, up until the error occurs. From my understanding the error should be logged as well, but it does not. Here’s an example of a log file:

Godot Engine v3.2.3.stable.mono.official - https://godotengine.org
OpenGL ES 3.0 Renderer: GeForce RTX 2070/PCIe/SSE2

Mono: Log file is: ‘C:/Users//AppData/Roaming/Godot/app_userdata/endless-runner-v2/mono/mono_logs/2020_12_21 13.03.14 (17128).txt’
Editions/Cowboy

It crashed at this point due to the program not being able to find a folder, which I forgot to create. But the error was never logged. The error appears shortly in the debug window, so the only way to find it was to monitor the debug log.

This is a pretty important feature to work for me, since without it makes debugging errors on releases impossible. From what I could read, this should work, so I think the error might be releated to C#, but I’m unsure. Anyone have an idea how to fix this
?

While I don’t know any Godot-specific details, I assume this is related to the flush timing of the stdout/stderr streams. AFAIK, there’s no way to control that timing in Godot.

For performance reasons, most logging implementations don’t write each log request immediately to disk. Instead, the requests are held in memory and then batched to disk periodically. So, I’d guess that a set of log entries are in the write buffer at the time the crash happens, and therefore never make it to disk.

In case you haven’t see it, here’s a good article on Godot debug logging:

https://medium.com/@silocoder/using-log-files-to-debug-godot-game-engine-apps-14c191df6580

jgodfrey | 2020-12-21 15:52