I am working with an application (set) using Nlog - and need to make an adjustment to log file base location. Up to this point they are based on ${basedir} which ends up in C:/Program Files/ for release/install builds and inside the visual studio project directory for debugging (C:\CustomDevelopment\Company\Code\Code - Trunk - MarkDev - Apr16\DebugOutput\logs ) ...
This location is problematic for 2 reasons: (1) security - install directory is wrong place for writable files, and (2) space - C drive is often relatively small and sensitive to file space exhaustion.
I am relying on static definition of Nlog.Config and proper placement of this file during the build process (Visual Studio, .Net...). A current snippet from this file (as example) is one of targets:
<target xsi:type="File" name="RobotMovement" fileName="${basedir}/logs/RobotMovement/${logger} ${appdomain:format={1\}} ${shortdate}.log"
layout="${longdate} | ${logger} | ${uppercase:${level}} | ${message} | ${exception:format=toString}" concurrentWrites="true" keepFileOpen="true" />
I have searched (somewhat unsuccessfully) for ways to influence this location, and my intended choice (unless advised otherwise) is the following:
(1) add a custom variable to the Nlog.Config file as in:
<!-- optional, add some variables
-->
<variable name="logBasedir" value="TO_BE_SUBSTITUTED"/>
(2) then change targets to be of form
<target xsi:type="File" name="RobotMovement" fileName="${logBasedir}/logs/RobotMovement/${logger} ${appdomain:format={1\}} ${shortdate}.log"
layout="${longdate} | ${logger} | ${uppercase:${level}} | ${message} | ${exception:format=toString}" concurrentWrites="true" keepFileOpen="true" />
(3) at build time (pre-build event), run a custom build tool on Nlog.Config file to find&replace "TO_BE_SUBSTITUTED" with an appropriate (configured ) location based on build type
typically something like find&replace "TO_BE_SUBSTITUTED" with "D:/Company/Product/Nlogs"
Am I missing some alternative best practice approach(s) ? This approach seems heavy-handed and crude, though it works. I read about moving the Config into the application - creating a configuration in code dynamically. This seems equally heavy-handed to accomplish such a small change. Thanks in advance.
MarkO