I could realize the last suggestion from ASerge (thank you very much for your help) in a demo program and it works! (on Windows)
I'm not sure how difficult it would be for me to convert my console program into an "Application". I'm not familiar with Applications and don't know how to insert my code into Application.Run() and more. So if there are other solutions, I'm interested in them (especially if they work with or can be "translated" to Linux):
Yes, now it is not a small console application. It is possible to choose another solution, but we need to understand what else your application should do.
Here is what my small console application does: it is started together with the OS via AutoStart and runs all the time in the background until OS shuts down. Every 30 seconds it looks for certain programs/processes if they are running and if yes, writes this into a SQLite database.
My program can run twice at a time: once in the background (see above) and secondly in the foreground using some command line parameters to show statistics or to control or kill the background program. I have this program finished for Windows and Linux (Ubuntu). Now I want to write a message into the logfile, when the OS (Windows or Linux) shuts down.
Thanks again to all for your help.