简体   繁体   中英

Where is ${basedir} located, using NLog?

Unless I'm totally missing it, I'm under the impression that the NLog documentation uses ${basedir} in its examples, without explaining what its location is supposed to be.

Where can I find information that lists all possible options with a meaningful description?

I have this configuration defined:

<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" throwExceptions="true">
  <targets>
    <target name="file" xsi:type="File"
                layout="${longdate} ${logger} ${message}"
                fileName="${basedir}/logs/${shortdate}.txt"
                keepFileOpen="false"
                encoding="iso-8859-2" />
  </targets>
  <rules>
    <logger name="*" minlevel="Debug" writeTo="file" />
  </rules>
</nlog>

It works as far as I can tell, but I haven't got a clue where it logs anything at.

${basedir} — Directory where the application runs, aka. AppDomain.BaseDirectory

I think, you will find this manual page helpful.

Based on already provided answers and comments, the answer can be summed up for .NET application:

AppDomain.CurrentDomain.BaseDirectory

For Console or Windows Forms application, this directory is bin/debug while within Visual Studio. If application is deployed, the path will most probably be the executable path.

For Web applications (ASP.NET) this will be the Web application root directory.

Not seeing any files may be triggered by several causes that include: NLog configuration errors and not being able to write the target file. To expose these errors make sure that NLog.config (or Nlog configuration embedded within web.config or app.config) specifies an internal log file to output such errors:

<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      internalLogFile="C:\NLogError\NLog.log">

<!-- targets and rules come here -->

</nlog>

Another possibility for failure is that if you are using NLog.config, NLog can't find the config file. Set the file to Copy Always in your build and it will end up in your bin directory, so NLog can find it at runtime.

If you copy the NLog configuration info to your App.config, you won't have this problem.

It depends also of the platform. For regular .Net projects it's indeed bin or bin/debug etc. (depending of your build settings)

For coreclr / aspnet5 it's the bin folder of your dnx runtime. That's still work in progress.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM