I have a class in C# that saves an error message in a log file in case of an exception. Now I want to save the log file in the same folder containing the application’s (in my case, a website) files. I tried using Environment.CurrentDirectory however it is not retrieving the path to my website. What can I do please to make use of a relative file path which points inside the website’s directory?
Here is the class’ code. As you can see, the path is absolute. I want to change it to a relative file path pointing to a folder in my website’s directory.
Usually
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)returns the path where the current assembly resides. You could useto create the log file name.
Question is really whether logging to the application’s folder is permitted by the OS. Also, for Web-applications, the log file would be publically visible and accessible through the web browser.