首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NLog将默认设置为相对路径

NLog将默认设置为相对路径
EN

Stack Overflow用户
提问于 2017-10-03 21:30:54
回答 1查看 881关注 0票数 1

我希望使用 in NLog (NLog.Extended NuGet包是特定的)来执行如下操作:

代码语言:javascript
复制
<variable name="logDir" value="${appsetting:name=RemoteLogDir:default=.\Log}" />

当我发布我的应用程序时,我设置了RemoteLogDir,但是回到了一个相对的目录中进行本地开发。我已经找到了一条绝对可行的工作之路,但这似乎不太适合合作者。

,我如何才能找到一条相对的工作之路?或者我需要提交一个特性请求?

备注:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
      autoReload="true" throwExceptions="false">

  <variable xsi:type="NLogVariable" name="appLogName" value="MyApp"/>

  <variable xsi:type="NLogVariable" name="logDir" value="${appsetting:name=RemoteLogDir:default=\.\\Log}" />
  <variable xsi:type="NLogVariable" name="layout" value="${level:uppercase=true} | ${date:format=MM/dd/yyyy HH\:mm\:ss} | ${machinename} | ${windows-identity:domain=true} | ${callsite} ${newline}    ${message}${onexception:${newline}[EXCEPTION]${newline}${exception:format=tostring}}" />

  <variable xsi:type="NLogVariable" name="logFileName" value="${var:logDir}/${var:appLogName}_${date:format=yyyy-MM-dd}.txt" />
  <variable xsi:type="NLogVariable" name="archiveLogFileName" value="${var:logDir}/Archive/${var:appLogName}_Archived_{#}.txt" />

  <targets>
    <target name="singleFile" xsi:type="File"
              layout="${var:layout}"
              fileName="${var:logFileName}"
              concurrentWrites="true"
              keepFileOpen="true"
              archiveFileName="${var:archiveLogFileName}"
              archiveEvery="Day"
              archiveNumbering="Date"
              archiveDateFormat="yyyy-MM-dd_HH"
              maxArchiveFiles="30" />
  </targets>

  <rules>
    <logger name="*" minlevel="Trace" writeTo="singleFile" />
  </rules>
</nlog>
EN

回答 1

Stack Overflow用户

发布于 2017-10-04 21:59:00

TL;博士

代码语言:javascript
复制
<variable xsi:type="NLogVariable" name="logDir" value="${whenEmpty:whenEmpty=${basedir}/Log:inner=${appsetting:name=RemoteLogDir}}" />

解释

实际上,应用程序只接受默认值的字符串。但是,您可以通过不提供默认值并使用whenEmpty来模拟所需的功能。当未设置应用程序设置时,内部值将被计算为空,因此呈现whenEmpty值。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46553740

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档