NLog / NLog.WindowsIdentity

NLog extensions for displaying User Windows Identity and target wrapper for user impersonation
BSD 3-Clause "New" or "Revised" License
1 stars 2 forks source link
authentication csharp dotnet identity nlog nlog-target

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:

```xml
<PackageReference Include="NLog.WindowsIdentity" Version="5.*" />
```

2) Add to your nlog.config:

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

Alternative register from code using fluent configuration API:

```csharp
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>