<envSettings>
<environment name="Local">
<add key="ElasticSearch.Url" value="http://localhost:9200/" />
</environment>
<environment name="Dev">
<add key="ElasticSearch.Url" value="http://XXXXXXX:9200/" />
</environment>
</envSettings>
<nlog autoReload="true" xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
throwExceptions="false">
<variable name="elastic.url" value="${envSettings:name=ElasticSearch.Url}"/> </nlog>
NLog是否可以从EnvSettings读取值?我已经使用了NLog.Extended nuget包。
答案 0 :(得分:1)
Rolf注意到,您可能需要一个自定义布局渲染器,因为最接近的内容读取System.Environment(例如${environment:variable=PATH}
)
然后编写代码:
// register ${ElasticSearch-Url}
LayoutRenderer.Register("ElasticSearch-Url", (logEvent) => retrieve ElasticSearch.url here);
请尽快执行此操作,例如main()
,app_start
等中