Details
Description
As mentioned in LOG4NET-429 and LOG4NET-421 (introduced in LOG4NET-205), having a custom property in a layout pattern makes each each log event resolve the (Windows) user name with
log4net.Core.LoggingEvent.get_UserName()
which calls
System.Security.Principal.WindowsIdentity.GetCurrent()
On Linux this leads to an internal exception:
System.PlatformNotSupportedException: Windows Principal functionality is not supported on this platform.
This happens with versions 2.0.10 and 2.0.11 on .NET Core 2.2 and .NET Core 3.1.
I attached a small console application project for reproduction in a docker image:
- Extract the zip
- Run docker build . -f Dockerfile -t log4net.test:latest to build a Linux docker image and compile the code
- Run docker run --name l4n -it --rm log4net.test:latest to run that image in a docker container and open an interactive shell
- And in the shell, run dotnet ConsoleApp1.dll to execute the compiled assembly
With internal debugging enabled, this produces the following console output:
log4net: log4net assembly [log4net, Version=2.0.11.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a]. Loaded from [/app/log4net.dll]. (.NET Runtime [3.1.8] on Unix 4.19.128.0) log4net: defaultRepositoryType [log4net.Repository.Hierarchy.Hierarchy] log4net: Creating repository for assembly [ConsoleApp1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null] log4net: Assembly [ConsoleApp1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null] Loaded From [/app/ConsoleApp1.dll] log4net: Assembly [ConsoleApp1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null] does not have a RepositoryAttribute specified. log4net: Assembly [ConsoleApp1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null] using repository [log4net-default-repository] and repository type [log4net.Repository.Hierarchy.Hierarchy] log4net: Creating repository [log4net-default-repository] using type [log4net.Repository.Hierarchy.Hierarchy] log4net: configuring repository [log4net-default-repository] using file [/app/ConsoleApp1.log4net.config] log4net: configuring repository [log4net-default-repository] using stream log4net: loading XML configuration log4net: Configuring Repository [log4net-default-repository] log4net: Configuration update mode [Merge]. log4net: Logger [root] Level string is [DEBUG]. log4net: Logger [root] level set to [name="DEBUG",value=30000]. log4net: Loading Appender [Log] type: [log4net.Appender.RollingFileAppender] log4net: Setting Property [File] to String value [Logs/ConsoleApp1] log4net: Setting Property [AppendToFile] to Boolean value [True] log4net: Setting Property [LockingModel] to object [log4net.Appender.FileAppender+InterProcessLock] log4net: Setting Property [RollingStyle] to RollingMode value [Date] log4net: Setting Property [StaticLogFileName] to Boolean value [False] log4net: Setting Property [DatePattern] to String value [-yyyy-MMMM\.\l\o\g] log4net: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False] log4net: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False] log4net: Setting Property [ConversionPattern] to String value [%date [%property{pid}|%3thread] %-5level %message%newline] log4net: Converter [date] Option [] Format [min=-1,max=2147483647,leftAlign=False] log4net: Converter [literal] Option [ [] Format [min=-1,max=2147483647,leftAlign=False] log4net: Converter [property] Option [pid] Format [min=-1,max=2147483647,leftAlign=False] log4net: Converter [literal] Option [|] Format [min=-1,max=2147483647,leftAlign=False] log4net: Converter [thread] Option [] Format [min=3,max=2147483647,leftAlign=False] log4net: Converter [literal] Option [] ] Format [min=-1,max=2147483647,leftAlign=False] log4net: Converter [level] Option [] Format [min=5,max=2147483647,leftAlign=True] log4net: Converter [literal] Option [ ] Format [min=-1,max=2147483647,leftAlign=False] log4net: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False] log4net: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False] log4net: Setting Property [Layout] to object [log4net.Layout.PatternLayout] log4net: Type = [0], r0 = [-1970-January.log], r1 = [-1970-January.log] log4net: Type = [1], r0 = [-1970-January.log], r1 = [-1970-January.log] log4net: Type = [2], r0 = [-1970-January.log], r1 = [-1970-January.log] log4net: Type = [3], r0 = [-1970-January.log], r1 = [-1970-January.log] log4net: Type = [4], r0 = [-1970-January.log], r1 = [-1970-January.log] log4net: Type = [5], r0 = [-1970-January.log], r1 = [-1970-February.log] log4net: Searched for existing files in [/app/Logs] log4net: curSizeRollBackups starts at [0] log4net: Opening file for writing [/app/Logs/ConsoleApp1-2020-September.log] append [True] log4net: Created Appender [Log] log4net: Adding appender named [Log] to logger [root]. log4net: Hierarchy Threshold [] log4net:ERROR [RollingFileAppender] ErrorCode: GenericFailure. Failed in DoAppend System.PlatformNotSupportedException: Windows Principal functionality is not supported on this platform. at System.Security.Principal.WindowsIdentity.GetCurrent() at log4net.Core.LoggingEvent.get_UserName() at log4net.Core.LoggingEvent.CreateCompositeProperties() at log4net.Core.LoggingEvent.LookupProperty(String key) at log4net.Layout.Pattern.PropertyPatternConverter.Convert(TextWriter writer, LoggingEvent loggingEvent) at log4net.Layout.Pattern.PatternLayoutConverter.Convert(TextWriter writer, Object state) at log4net.Util.PatternConverter.Format(TextWriter writer, Object state) at log4net.Layout.PatternLayout.Format(TextWriter writer, LoggingEvent loggingEvent) at log4net.Appender.AppenderSkeleton.RenderLoggingEvent(TextWriter writer, LoggingEvent loggingEvent) at log4net.Appender.TextWriterAppender.Append(LoggingEvent loggingEvent) at log4net.Appender.FileAppender.Append(LoggingEvent loggingEvent) at log4net.Appender.RollingFileAppender.Append(LoggingEvent loggingEvent) at log4net.Appender.AppenderSkeleton.DoAppend(LoggingEvent loggingEvent)
Attachments
Attachments
Issue Links
- is cloned by
-
LOG4NET-653 BufferingAppenderSkeleton.Append throws exception on arm64 linux by calling WindowsIdentity.GetCurrent
- Resolved