Uploaded image for project: 'Log4net'
  1. Log4net
  2. LOG4NET-694

log4net appender string comparison is culture dependent which can cause problems with certain cultures

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.0.14
    • None
    • Appenders
    • None
    • Windows 10 x64 2202

    Description

      log4net has a lot of places where string comparison is not culture agnostic, meaning certain string comparison is culture specific, which can be a bad thing.

      This has been seen with version 2.0.15 (there is no affected version to set to reflect this ..)

      Specifically this is an issue with Windows and the Thai language (th-TH culture).

      I believe this technically only affects log4net users who are on net5 (or maybe net core 3 and above) and newer?.

      The issue is provoked in net5 and up as the runtime handles culture differently than from the previous .net framework's due to the transition from NLS (National Language Support), to ICU: https://learn.microsoft.com/en-us/dotnet/core/extensions/globalization-icu

      I believe using culture agnostic string comparison is the way to go to fix this issue:

      someString.IndexOf("someStringValue", StringComparison.Ordinal)

      Here is an excerpt from a Thai system where we discovered this issue where the rolling file appender fails:

      LoggingService.Config: Trying to write default (embedded) file to standard path C:\ProgramData\Swing Catalyst\settings\log4net.xml
      log4net:ERROR Could not create Appender [RollingFileAppender] of type [log4net.Appender.RollingFileAppender]. Reported error follows.
      System.ArgumentOutOfRangeException: startIndex cannot be larger than length of string. (Parameter 'startIndex')
         at System.String.ThrowSubstringArgumentOutOfRange(Int32 startIndex, Int32 length)
         at System.String.Substring(Int32 startIndex)
         at log4net.Appender.RollingFileAppender.GetBackUpIndex(String curFileName)
         at log4net.Appender.RollingFileAppender.InitializeFromOneFile(String baseFile, String curFileName)
         at log4net.Appender.RollingFileAppender.InitializeRollBackups(String baseFile, ArrayList arrayFiles)
         at log4net.Appender.RollingFileAppender.DetermineCurSizeRollBackups()
         at log4net.Appender.RollingFileAppender.ExistingInit()
         at log4net.Appender.RollingFileAppender.ActivateOptions()
         at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
      
      log4net:ERROR Appender named [RollingFileAppender] not found.
      

       

       

      https://learn.microsoft.com/en-us/dotnet/core/extensions/performing-culture-insensitive-string-comparisons

      Some related / similar issues for further context:

      Attachments

        Activity

          People

            Unassigned Unassigned
            stianeklund Stian Eklund
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: