shpaass / yafc-ce

Powerful Factorio calculator/analyser that works with mods
GNU General Public License v3.0
51 stars 18 forks source link

[Discussion] Replace Console.WriteLine with proper logging #54

Closed shihan42 closed 1 month ago

shihan42 commented 6 months ago

The various Console.WriteLines that are scattered around don't do anything on Windows, since the project compiles to a "Windows application" and hence no terminal is available.

Perhaps it is a good idea to replace them with proper logging (e.g. NLog, Serilog, ...).

Question: Is there any output if YAFC is started from a terminal in Linux?

veger commented 6 months ago

Oh... I just added these to your PR as an advice to use, as I was assuming that those would be shown in Windows as well, since those are official C# stdlib functions...

Interesting those do not work on Windows, on Linux Console.WriteLine() shows fine, as C# is a Microsoft invention. I suppose SDL is blocking them for Windows or something?

Edit I did a quick search whether SDL is indeed blocking them and these is some info on the subject:

(I didn't have time to fully read the articles, but hopefully there is something in that could help?)

shihan42 commented 6 months ago

With conditional compilation and proper usage of AttachConsole, we can enable console output on Windows, if the process is started from the terminal. With that in mind we can provide proper outputs for any platform.

Any interest in support for logfiles?

Dorus commented 6 months ago

Perhaps it is a good idea to replace them with proper logging (e.g. NLog, Serilog, ...).

Just my 2 cent, but with dotnet core C# has pretty decent native logging and those packages offer little to nothing extra.

see https://learn.microsoft.com/en-us/dotnet/core/extensions/logging?tabs=command-line

You can then add a logging providers to write the log messages to an appropriate channel.

shihan42 commented 6 months ago

Fair enough. Better to use parts of the standard than importing NuGets (if the benefit of external packages is negligible).

The questions stands: Any interest for logfiles?

shpaass commented 6 months ago

Any interest for logfiles?

If you meant "do we need them?", I'd say do it only if you want to implement them. They are good for debugging, but the scale of this project is not big enough to require an elaborate logging system.

shihan42 commented 6 months ago

Perhaps I'll work on this, but not right now. You're right, they aren't necessary at the moment.

shihan42 commented 4 months ago

After some research, I absolutely second @Dorus.

I'd implement a FileLoggingProvider for Microsoft.Extensions.Logging. It integrates well with the rest of .Net and sports some fancy source-generation.