RurouniJones
RurouniJones

Reputation: 53

Optional spaces between multiple layout renderers?

I think I must be missing something extremely obvious here but furious doc reading and googling has failed me. I have the following layout for a file name:

<target name="asyncLogFile" xsi:type="AsyncWrapper" queueLimit="5000" overflowAction="Discard" >
      <target name="mainLogFile" xsi:type="File" fileName="logs/${mdlc:item=GameServer:whenEmpty=Main} ${mdlc:item=Controller}.log"
              layout="${longdate} ${level:uppercase=true} | ${logger} | ${message} ${exception:format=toString,Data:maxInnerExceptionLevel=3}" />
    </target>

The MDLC items can both be null, in the games of the GameServer it gets replaced with "Main" and the Controller doesn't matter (If the GameServer is null then the Controller will be null).

However this means that if GameServer is null I end up with

Main .log Because of the space I have between the two mdlc entries. How can I make that space optional as part of the GameServer mldc entry!? I have looked at :pad to add a space after the but that doesn't seem to work. I have tried concatenating the mdlc's but that doesn't work.

I was expecting something simple you could add as an ambient property like :suffix but nothing like that exists.

Again I think I must be missing something basic here but it eludes me.

Upvotes: 0

Views: 127

Answers (2)

Rolf Kristensen
Rolf Kristensen

Reputation: 19867

Same ugly, but faster because of less allocation:

    <variable name="GameServerLogFile" value="${when:when='${mdlc:item=GameServer}'=='':inner=Main:else=${mdlc:item=GameServer} ${mdlc:item=Controller}}" />

    <targets>
       <target name="mainLogFile" xsi:type="File" fileName="logs/${GameServerLogFile}.log" />
    </targets>

Better to compare against empty-string '', than to call length()-method.

Upvotes: 1

RurouniJones
RurouniJones

Reputation: 53

Ugly but this works

<target name="mainLogFile" xsi:type="File" fileName="logs/${when:when=length('${mdlc:item=GameServer}') > 0:inner=${mdlc:item=GameServer} ${mdlc:item=Controller}:else=Main}.log"

Upvotes: 1

Related Questions