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

Error parsing layout windows-identity will be ignored (.NET Core 2.1) #3029

Closed
abakumov-v opened this issue Nov 26, 2018 · 10 comments
Closed

Comments

@abakumov-v
Copy link

Hi!

NLog version: 4.5.11

Platform: .NET Core 2.1 Console application

Current NLog config (xml or C#, if relevant)

<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      autoReload="true"
      throwExceptions="false"
      keepVariablesOnReload="true"
      internalLogFile="c:\temp\nlog\My.Custom.Service\internal-nlog.txt">

  <!-- enable asp.net core layout renderers -->
  <extensions>
    <add assembly="NLog.Web.AspNetCore"/>
  </extensions>

  <variable name="logFolder" value="c:\temp\nlog\My.Custom.Service" />
  <variable name="appVersion" value="${assembly-version:name=My.Custom.Console}" />

  <!-- the targets to write to -->
  <targets>
    <!-- write logs to file  -->
    <target xsi:type="File" name="allFile" fileName="${var:logFolder}\${shortdate}-nlog-all.console.log"
            layout="${var:appVersion}|${longdate}|${event-properties:item=EventId.Id}|${uppercase:${level}}|${logger}|${message} ${exception}" />

    <!-- another file log, only own logs. Uses some ASP.NET core renderers -->
    <target xsi:type="File" name="ownFile" fileName="${var:logFolder}\${shortdate}-nlog-own.console.log"
            layout="${var:appVersion}|${longdate}|${event-properties:item=EventId.Id}|${uppercase:${level}}|${logger}|${message} ${exception}" />

    <target xsi:type="File" name="quartzFile" fileName="${var:logFolder}\${shortdate}-nlog-quartz.console.log"
            layout="${var:appVersion}|${longdate}|${event-properties:item=EventId.Id}|${uppercase:${level}}|${logger}|${message} ${exception}" />

    <target name="dbLogAsync" xsi:type="AsyncWrapper" batchSize="20">
      <target name="dbLog" xsi:type="Database"
              commandType="StoredProcedure"
              commandText="[dbo].[writeLogs]">
        <!--Set connection string for NLog that used in Startup.cs-->
        <connectionString>${var:connectionString}</connectionString>
        <parameter name="@level" layout="${level}" />
        <parameter name="@logger" layout="${logger}" />
        <parameter name="@message" layout="${message}" />
        <parameter name="@exception" layout="${exception:format=toString:separator=&#13;&#10;}" />
        <parameter name="@stackTrace" layout="${stacktrace:format=Raw:topFrames=10:skipFrames=0:separator=&#13;&#10;}" />
        <parameter name="@user" layout="${windows-identity}" />        
        <parameter name="@server" layout="${machinename}" />
        <parameter name="@applicationName" layout="My.Custom.Console" />
        <parameter name="@applicationVersion" layout="${var:appVersion}" />
        <parameter name="@callSource" layout="${callsite}" />
        <parameter name="@callSourceLineNumber" layout="${callsite-linenumber}" />
      </target>
    </target>

    <!-- write to the void aka just remove -->
    <target xsi:type="Null" name="blackhole" />
  </targets>

  <!-- rules to map from logger name to target -->
  <rules>
    <!--All logs, including from Microsoft-->
    <logger name="*" minlevel="Trace" writeTo="allFile" />
    <!--Skip Microsoft logs and so log only own logs-->
    <logger name="Microsoft.*" minlevel="Trace" writeTo="blackhole" final="true" />
    <!--Quartz logs writes to another file-->
    <logger name="Quartz.*" minLevel="Trace" writeTo="quartzFile" final="true" />
    <logger name="Scheduler.Quartz.*" minLevel="Trace" writeTo="quartzFile" final="true" />

    <logger name="*" minlevel="Trace" writeTo="ownFile" />
    <logger name="*" minlevel="Trace" writeTo="dbLogAsync" />

  </rules>
</nlog>
  • What is the current result?

In internal-nlog.txt I see this message:

2018-11-26 13:40:38.6030 Info Loading assembly: NLog.Web.AspNetCore
2018-11-26 13:40:38.6703 Info Adding target File Target[allFile]
2018-11-26 13:40:38.6703 Info Adding target File Target[ownFile]
2018-11-26 13:40:38.6703 Info Adding target File Target[quartzFile]
2018-11-26 13:40:38.7894 Error Error parsing layout windows-identity will be ignored. Exception: System.ArgumentException: LayoutRenderer cannot be found: 'windows-identity'
   at NLog.Config.Factory`2.CreateInstance(String name)
   at NLog.Layouts.LayoutParser.GetLayoutRenderer(ConfigurationItemFactory configurationItemFactory, String name)

And in my database table the column 'User' contains empty string.

  • What is the expected result?

The windows-identity layout renderer will work correctly and send the identity info to all targets.

Yes

  • Please post full exception details (message, stacktrace, inner exceptions)
System.ArgumentException: LayoutRenderer cannot be found: 'windows-identity'
   at NLog.Config.Factory`2.CreateInstance(String name)
   at NLog.Layouts.LayoutParser.GetLayoutRenderer(ConfigurationItemFactory configurationItemFactory, String name)
  • Are there any workarounds?

Yes - you need install the NLog.WindowsIdentity package and add it to nlog.config inside <extensions> section - for example:

  <extensions>
    <add assembly="NLog.WindowsIdentity"/>
  </extensions>
  • Is there a version in which it did work?

No

  • Can you help us by writing an unit test?

Mm... I don't know

@abakumov-v
Copy link
Author

Updated page https://github.com/NLog/NLog/wiki/Windows-Identity-Layout-Renderer - added info on top of article about using package NLog.WindowsIdentity

@304NotModified
Copy link
Member

304NotModified commented Nov 28, 2018

  • What is the expected result?

The windows-identity layout renderer will work correctly and send the identity info to all targets.

I can't only work if you include the extension (package)?

@abakumov-v
Copy link
Author

@304NotModified sorry, but I'm not understood your question....

@304NotModified
Copy link
Member

304NotModified commented Nov 29, 2018

I don't know why you expect it would work, as the windows-identity isn't in the main package. I think your expectations are wrong here.

@abakumov-v
Copy link
Author

abakumov-v commented Nov 29, 2018

@304NotModified because there is no information about the Nlog.WindowsIdentity package - neither https://nlog-project.org/config/?tab=layout-renderers&search=identity nor https://github.com/NLog/NLog/wiki/Windows-Identity-Layout-Renderer. So I suggested that windows-identity should work out of the box.

But since it turned out to be wrong, then I added information about this package to https://github.com/NLog/NLog/wiki/Windows-Identity-Layout-Renderer (and I dont know how to add this info to page https://nlog-project.org/config/?tab=layout-renderers&search=identity ...)

@304NotModified
Copy link
Member

yes it's a documentation issue then.

@304NotModified
Copy link
Member

@abakumov-v
Copy link
Author

Create new issue for NLog.github.io - NLog/NLog.github.io#75
I will fix this issue later today

@304NotModified
Copy link
Member

thanks in advance!

@304NotModified
Copy link
Member

I assume your question has been answered, if not, please let us know!

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