No, from this fragment of code, you don't know exact location of the file. It is "working directory" (also called "current directory"), and this directory depends on where you start the application. If you simply click on the .exe file, it is equivalent to "cd" command wiuth the directory where the executable file is located, followed by the executable file name as the next command, which starts the application. So, in this case, working directory would be the same as executable directory. This is not so in general case; you can start the same executable from any other directory. Such directory can even be read-only for the current user, which would make this kind of logging impossible.
This is "naive" logging which can help you in some simple cases, but
is not robust enough to be practical. Recommended way of logging is through the use
System.Diagnostics.EventLog
:
https://msdn.microsoft.com/en-us/library/system.diagnostics.eventlog%28v=vs.110%29.aspx[
^].
This is a whole logging system, which allows you, in addition to default logging to the system event log, create your own custom sinks for logging data, or classify your logging information in the system log according to the application. Please see my past answers on logging customization:
MsBuild OutPut to the TextBox on the fly in Windows Application[
^],
How to create event log under a folder[
^].
Another recommended way of logging in .NET applications would be open-source using Apache log4net:
https://logging.apache.org/log4net[
^].
—SA