I have an application that logs, and I don't get any file-based logging when I deploy it to the default directory. It seems clear that the reason is that writing to "c:\program files (x86)\blah" requires elevated privelege levels which my app doesn't have. So I end up telling users "install to "c:\blah" and it will work fine, which it does. But that seems rubbish. Any alternative?
You could configure NLog to log to a different folder. NLog has SpecialFolderLayoutRenderer that allows you to use .NET's special folders. You should be able to specify the log file name using the SpecialFolderLayoutRenderer. Maybe something like this (I have not tried this):
<target name="file" xsi:type="File" layout="${longdate} | ${logger} | "${level} | ${message}" fileName="${specialfolder:folder=MyDocuments:dir=LogFiles:file=${shortdate}.log}" />
That should (if it works) create log files in a LogFiles
subfolder in the user's Documents
folder, with the actual log file names corresponding to the date. I don't know, but I would guess that NLog will create the LogFiles folder the first time anything is logged.
Good luck!
For me it worked like this:
fileName="${specialfolder:folder=ApplicationData}/newDMS ClientApplication/Logs/${shortdate}.log"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With