log4net SDK Reference

LoggingEvent.UserName Property

Gets the name of the current user.

[Visual Basic]
Public ReadOnly Property UserName As String
[C#]
public string UserName {get;}

Property Value

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

Remarks

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:

Method Results
WindowsIdentity.GetCurrent() 10000 loops, 00:00:00.2031250 seconds
WindowsIdentity.GetCurrent().Name 10000 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

LoggingEvent Class | log4net.Core Namespace