How to change or configure basedir to a relative path?

5,419 views
Skip to first unread message

lmttag

unread,
Nov 14, 2012, 4:23:46 PM11/14/12
to nlog-...@googlegroups.com
Hello.
I just started using NLog with an ASP.NET MVC project and have been trying to find a way to change (or override) basedir to a relative path.

In my Web.config, I have:

<target name="logfile" xsi:type="File" fileName="${basedir}/Logs/${date:format=yyyy-MM-dd}-applog.log" />

but I don't want the log files to go to ${basedir}/Logs/...  I need the files to go to go to a relative one folder up - ..\Logs\...  I tried:

<target name="logfile" xsi:type="File" fileName="../Logs/${date:format=yyyy-MM-dd}-applog.log" /> and
<target name="logfile" xsi:type="File" fileName="..\Logs\${date:format=yyyy-MM-dd}-applog.log" />

and neither worked.  No log file was written.

So, how can I configure NLog to write the log files to a relative path?

Thanks.

Kim Christensen

unread,
Nov 22, 2012, 7:54:27 PM11/22/12
to nlog-...@googlegroups.com
Does it work if you specify an absolute path?
It should be possible to specify a relative path. Could you post the complete config file?

lmttag

unread,
Nov 27, 2012, 9:54:49 AM11/27/12
to nlog-...@googlegroups.com
Hello Kim.  Thanks for replying.  Yes, it works if I specify an absolute path.  Unfortunately, our app can be installed anywhere on a customer's computer and the absolute path may not be available (or wanted by the customer).  This is why we'd like to have the relative path (probably just one level up from where the web.config file is located).  Below is our current web.config file.  (Note: it doesn't use a relative path because it wouldn't work for us.)

<?xml version="1.0" encoding="utf-8"?>
<configuration>
 
<configSections>
   
<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
 
</configSections>
 
<nlog autoReload="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   
<targets>
     
<target name="logfile" xsi:type="File" fileName="${basedir}/Logs/${date:format=yyyy-MM-dd}-app.log" />
   
</targets>
   
<rules>
     
<logger name="*" minlevel="Trace" writeTo="logfile" />
   
</rules>
 
</nlog>
 
<connectionStrings>
   
<add name="DbConnectionString" providerName="System.Data.SqlClient" connectionString="Data Source=localhost;Initial Catalog=CompanyDb;Integrated Security=SSPI;Persist Security Info=False" />
 
</connectionStrings>
 
<appSettings>
   
<add key="webpages:Version" value="2.0.0.0" />
   
<add key="webpages:Enabled" value="true" />
 
</appSettings>
 
<system.web>
   
<compilation debug="true" targetFramework="4.5" />
   
<httpRuntime targetFramework="4.5" />
   
<authentication mode="None" />
   
<pages>
     
<namespaces>
       
<add namespace="System.Web.Helpers" />
       
<add namespace="System.Web.Mvc" />
       
<add namespace="System.Web.Mvc.Ajax" />
       
<add namespace="System.Web.Mvc.Html" />
       
<add namespace="System.Web.Optimization" />
       
<add namespace="System.Web.Routing" />
       
<add namespace="System.Web.WebPages" />
     
</namespaces>
   
</pages>
 
</system.web>
 
<system.webServer>
   
<modules runAllManagedModulesForAllRequests="false" />
   
<validation validateIntegratedModeConfiguration="true" />
   
<handlers>
     
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
     
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
     
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
     
<add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
     
<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
     
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
   
</handlers>
 
</system.webServer>
 
<runtime>
   
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
     
<dependentAssembly>
       
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
       
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
     
</dependentAssembly>
     
<dependentAssembly>
       
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
       
<bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
     
</dependentAssembly>
     
<dependentAssembly>
       
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
       
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
     
</dependentAssembly>
     
<dependentAssembly>
       
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
       
<bindingRedirect oldVersion="0.0.0.0-1.3.0.0" newVersion="1.3.0.0" />
     
</dependentAssembly>
   
</assemblyBinding>
 
</runtime>
</configuration>


Thanks.

Kim Christensen

unread,
Nov 29, 2012, 8:08:52 AM11/29/12
to nlog-...@googlegroups.com
Please create an issue on Github, and we can look into the problem
Reply all
Reply to author
Forward
0 new messages