Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fallback to Layout-Type-Alias when unknown LayoutRenderer #4964

Open
snakefoot opened this issue Jun 9, 2022 · 2 comments
Open

Fallback to Layout-Type-Alias when unknown LayoutRenderer #4964

snakefoot opened this issue Jun 9, 2022 · 2 comments

Comments

@snakefoot
Copy link
Contributor

snakefoot commented Jun 9, 2022

Instead of having to do this:

<target name="hello">
    <layout type="mylayout" />
</target>

Then it could be nice one could also do this:

<target name="hello" layout="${mylayout}" />

Right now the work-around is doing it like this:

<variable name="mylayout2">
      <layout type="mylayout" />
</variable>
<target name="hello" layout="${mylayout2}" />

Could also be nice with option-handling when doing the short-hand type-alias-syntax. Ex. layout="${mylayout:awesome=true}"

@srafay
Copy link

srafay commented Jul 28, 2022

I think this is available with NLog's current version. I am already using it and its working fine.

<!-- Define the layout to be used for console and file logging -->
<variable name="loggerLayout" value="[${longdate}] ${level:uppercase=true}${message}"/>
<target xsi:type="File" name="file" fileName="${basedir}\logs\${shortdate}.log"
        layout="${loggerLayout}" />

I have defined a variable for layout (only because I want to reuse it with other targets), but I think it still works if I directly define the layout in <target/>

<target xsi:type="File" name="file" fileName="${basedir}\logs\${shortdate}.log"
        layout="[${longdate}] ${level:uppercase=true}${message}" />

My packages:
NLog: 5.0.1
NLog.Web.AspNetCore: 5.1.0

@snakefoot
Copy link
Contributor Author

Yes I know the work-around (using config-variable) is working. My goal is to do it without the work-around:

<target xsi:type="File" name="file" fileName="${basedir}\logs\${shortdate}.log" layout="${jsonlayout:includeeventproperties=true}" />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants