Skip to content

NLog extensions for displaying User Windows Identity and target wrapper for user impersonation

License

Notifications You must be signed in to change notification settings

NLog/NLog.WindowsIdentity

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NLog.WindowsIdentity

NLog extensions for displaying User Windows Identity and target wrapper for user impersonation

Version AppVeyor

How to install

  1. Install the package

    Install-Package NLog.WindowsIdentity or in your csproj:

    <PackageReference Include="NLog.WindowsIdentity" Version="5.*" />
  2. Add to your nlog.config:

    <extensions>
        <add assembly="NLog.WindowsIdentity"/>
    </extensions>

    Alternative register from code using fluent configuration API:

    LogManager.Setup().SetupExtensions(ext => {
        ext.RegisterTarget<NLog.Targets.Wrappers.ImpersonatingTargetWrapper>();
        ext.RegisterLayoutRenderer<NLog.LayoutRenderers.WindowsIdentityLayoutRenderer>();
    });

Example of Windows Identity UserName

Example of NLog.config-file that outputs username from Windows Identity :

<nlog>
    <extensions>
        <add assembly="NLog.WindowsIdentity"/>
    </extensions>
    <targets>
        <target name="console" xsi:type="console" layout="${message}|User=${windows-identity}" />
    </targets>
    <rules>
        <logger minLevel="Info" writeTo="console" />
    </rules>
</nlog>

Example of Impersonating Windows Identity

Example of NLog.config-file that apply ImpersonatingWrapper :

<nlog>
    <extensions>
        <add assembly="NLog.WindowsIdentity"/>
    </extensions>
    <targets>
        <target name="userConsole" xsi:type="ImpersonatingWrapper" userName="xxx">
            <target name="console" xsi:type="console" layout="${message}|User=${windows-identity}" />
        </target>
    </targets>
    <rules>
        <logger minLevel="Info" writeTo="userConsole" />
    </rules>
</nlog>