簡體   English   中英

NLog.config 中值的條件

[英]Condition in value in NLog.config

我在NLog.config文件中創建自己的布局:

<variable name="MyLayout" value="${message}: ${exception:format=tostring}"/>

但是當沒有例外時,我仍然在我的日志文件:看到消息之后沒有任何內容。

我怎么能添加:只有在有例外的情況下? 也許是這樣的(不是工作代碼)

<variable name="MyLayout" value="${message}${exception != null ? ': ' : ''}${exception:format=tostring}"/>

你可以用${message}做到這一點

${message:exceptionSeparator= \: :withException=true}

或者你可以使用${oneexception}

${message}${onexception: \: }${exception:format=tostring}

注意:用作 NLog LayoutRenderer 的選項分隔符,因此必須對其進行轉義

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM