You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-user@logging.apache.org by Sascha Hamacher <sa...@arcor.de> on 2009/03/25 19:36:56 UTC

Dot in logger name is causing log4net to throw exception

Hello,
first of all thank you for the very good logging framework.
While working with Log4Net 1.2.10 I experienced the following problem:

When the logger name starts with a ".", LogManager.GetLogger fails with 
the following exception:

System.ArgumentOutOfRangeException was unhandled
 Message="Index was out of range. Must be non-negative and less than the 
size of the collection.\r\nParameter name: startIndex"
 Source="mscorlib"
 ParamName="startIndex"
 StackTrace:
      at System.String.LastIndexOf(Char value, Int32 startIndex, Int32 
count)
      at System.String.LastIndexOf(Char value, Int32 startIndex)
      at log4net.Repository.Hierarchy.Hierarchy.UpdateParents(Logger log)
      at log4net.Repository.Hierarchy.Hierarchy.GetLogger(String name, 
ILoggerFactory factory)
      at log4net.Repository.Hierarchy.Hierarchy.GetLogger(String name)
      at log4net.Core.LoggerManager.GetLogger(Assembly 
repositoryAssembly, String name)
      at log4net.LogManager.GetLogger(Assembly repositoryAssembly, 
String name)
      at log4net.LogManager.GetLogger(String name)
      at ReproCaseLog4Net.Program.Main(String[] args) in 
C:\Users\hamacs01\Documents\Visual Studio 
2008\Projects\ReproCaseLog4Net\ReproCaseLog4Net\Program.cs:line 20
      at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] 
args)
      at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence 
assemblySecurity, String[] args)
      at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
      at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
      at System.Threading.ExecutionContext.Run(ExecutionContext 
executionContext, ContextCallback callback, Object state)
      at System.Threading.ThreadHelper.ThreadStart()
 InnerException:


The following code of a simple command line program reproduces the 
problem for me:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using log4net.Appender;
using log4net.Config;
using log4net;
using log4net.Layout;

namespace ReproCaseLog4Net
{
 class Program
 {
   static void Main( string[] args )
   {
     BasicConfigurator.Configure( new ConsoleAppender()
     {
       Layout = new SimpleLayout()
     } );
     ILog log = LogManager.GetLogger( ".MyLogger" ); // <<--- the 
exception is thrown here
     log.Error( "ErrorMessage" );
     Console.ReadLine();
   }
 }
}




Best regards,
Sascha Hamacher