LoggingEventUserName Property Apache log4net™ SDK Documentation
Gets the name of the current user.

Namespace: log4net.Core
Assembly: log4net (in log4net.dll) Version: 4.0

public string UserName { get; }

Property Value

Type: String
The name of the current user, or NOT AVAILABLE when the underlying runtime has no support for retrieving the name of the current user.

Calls WindowsIdentity.GetCurrent().Name to get the name of the current windows user.

To improve performance, we could cache the string representation of the name, and reuse that as long as the identity stayed constant. Once the identity changed, we would need to re-assign and re-render the string.

However, the WindowsIdentity.GetCurrent() call seems to return different objects every time, so the current implementation doesn't do this type of caching.

Timing for these operations:

WindowsIdentity.GetCurrent()10000 loops, 00:00:00.2031250 seconds
WindowsIdentity.GetCurrent().Name10000 loops, 00:00:08.0468750 seconds

This means we could speed things up almost 40 times by caching the value of the WindowsIdentity.GetCurrent().Name property, since this takes (8.04-0.20) = 7.84375 seconds.

See Also