Saturday 15 January 2011

How to make a certain piece optional in a NLog layout pattern? -


I have a custom layout renderer whose name is Job it provides several items, which Our app Used in configurations like this:

  & lt; Variable name = "jobHost" value = "$ {job: item = host}" /> & Lt; Variable name = "jobService" value = "$ {Job: item = service}" /> & Lt; Variable name = "jobNS" value = "$ {job: item = ns}" /> & Lt; Variable name = "jobName" value = "$ {job: item = name}" /> & Lt; Variable name = "jobKind" value = "$ {job: item = type}" /> & Lt; Variable name = "jobScheduleId" value = "$ {job: item = schedule}" /> & Lt; $ {JobService} NS: $ {JOB NS} N: '$ {jobName}' K: $ {jobKind} S: $ {jobScheduleId}: variable name = "jobLayout" value = "[H: $ {jobHost} S: ] "/> & Lt; $ {Longdate} [$ {threadid}] $ {machinename} $ {jobLayout} $ {uppercase: inner = $ {level}} $ {logger} - $ {message} $ {Onexception} $ variable name = "layout" value = "$ {longdate} : $ {Newline} $ {exception: format = toString: innerFormat = ToString: maxInnerExceptionLevel = 2}} "/> & Lt; Goal & gt; & Lt; Target name = "threadlog" axis: type = "thread specific tag" /> & Lt; Target xsi: type = "SplitGroup" name = "All targets" & gt; & Lt; Target name = "textfile" xsi: type = "file" filename = "c: \ log \ quartzbackgroundEngine.txt" layout = "$ {layout}" /> & Lt; Target name = "console" xsi: type = "colored console" layout = "$ {layout}" /> & Lt; / Target & gt; & Lt; / Targets & gt;   

When the layout renderer decides that no job-specific data is available, then the string in the log message [H: S: NS: N: '' K: S: ] Contains . I want to take it out.

So, I tried to replace $ {jobLayout} with $ {jobLayout}: when = Job Name! = Â ???? A ????} , but it does not work because analog thinks that job layout should be in line with a variable rather than a layout renderer, which is a matter here.

How can I change my layout so that $ {jobLayout} only if $ {jobName} is not empty?

I have a problem where I wanted to display a particular formatting when a variable is not empty Was there.

I took some inspiration

P>

$ {when: when = length ('$ {jobName}') & gt; 0: Inside = $ {Job Layout}}

I'm not sure that you will get 100%, but this is a step in the right direction.

No comments:

Post a Comment