WolfgangHG opened a new issue, #332:
URL: https://github.com/apache/logging-log4net/issues/332

   There must have been a change in 3.4.0 that makes my code fail on my 
development machine: my Log4Net config defines an `EventLogAppender`, and this 
fails if the event log registry key is not set:
   
   `[EventLogAppender] ErrorCode: GenericFailure. Caught a SecurityException 
trying to access the EventLog.  Most likely the event source Sample Application 
doesn't exist and must be created by a local administrator.  Will disable 
EventLogAppender.  See 
http://logging.apache.org/log4net/release/faq.html#trouble-EventLog
   `
   
   My Log4Net config looks like this:
   
   ```xml
   <?xml version="1.0" encoding="utf-8" ?>
   <log4net>
     <appender name="EventLogAppender" 
type="Log4Net.Appenders.NetCore.EventLogAppender,Log4Net.Appenders.NetCore">
       <param name="LogName" value="Sample Log" />
       <param name="ApplicationName" value="Sample Application" />
   
       <layout type="log4net.Layout.PatternLayout">
         <conversionPattern value="%date [%thread] %-5level %logger - 
%message%newline" />
       </layout>
       <filter type="log4net.Filter.LevelRangeFilter">
         <levelMin value="ERROR" />
         <levelMax value="FATAL" />
       </filter>
     </appender>
   
     <root>
       <level value="INFO" />
       <appender-ref ref="EventLogAppender" />
     </root>
   
   </log4net>
   ```
   
   When activating Log4Net, I use `XmlConfigurator.ConfigureAndWatch` and fail 
if the resulting error collection contains anything - in this case logging is 
misconfigured and don't want to continue.
   
   With 3.4.0, the error messages contain an error (see above) if there is no 
key `Computer\HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\EventLog\Sample 
Log\Sample Application`. So my Log4Net initialization fails.
   
   With 3.3.2, there is no error message, the errors are caught internally.
   
   The error happens internally, the stack trace is the same for both versions:
   
   ```
   System.Security.SecurityException
     HResult=0x8013150A
     Message=Requested registry access is not allowed.
     Source=Microsoft.Win32.Registry
     StackTrace:
      at
        
Microsoft.Win32.Registry.dll!Microsoft.Win32.RegistryKey.OpenSubKey(string 
name, bool writable) Unknown
        
System.Diagnostics.EventLog.dll!System.Diagnostics.EventLog.GetEventLogRegKey(string
 machine, bool writable)    Unknown
        
System.Diagnostics.EventLog.dll!System.Diagnostics.EventLog.FindSourceRegistration(string
 source, string machineName, bool readOnly, bool wantToCreate) Unknown
        
System.Diagnostics.EventLog.dll!System.Diagnostics.EventLog.FindSourceRegistration(string
 source, string machineName, bool readOnly)    Unknown
        
System.Diagnostics.EventLog.dll!System.Diagnostics.EventLog.DeleteEventSource(string
 source, string machineName)        Unknown
        
Log4Net.Appenders.NetCore.dll!Log4Net.Appenders.NetCore.EventLogAppender.ActivateOptions()
      Unknown
        
log4net.dll!log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(System.Xml.XmlElement
 appenderElement)  Unknown
        
log4net.dll!log4net.Repository.Hierarchy.XmlHierarchyConfigurator.FindAppenderByReference(System.Xml.XmlElement
 appenderRef)    Unknown
        
log4net.dll!log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseChildrenOfLoggerElement(System.Xml.XmlElement
 catElement, log4net.Repository.Hierarchy.Logger log, bool isRoot)  Unknown
        
log4net.dll!log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseRoot(System.Xml.XmlElement
 rootElement)  Unknown
        
log4net.dll!log4net.Repository.Hierarchy.XmlHierarchyConfigurator.Configure(System.Xml.XmlElement
 element)      Unknown
        
log4net.dll!log4net.Repository.Hierarchy.Hierarchy.XmlRepositoryConfigure(System.Xml.XmlElement
 element)        Unknown
        
log4net.dll!log4net.Repository.Hierarchy.Hierarchy.log4net.Repository.IXmlRepositoryConfigurator.Configure(System.Xml.XmlElement
 element)       Unknown
        
log4net.dll!log4net.Config.XmlConfigurator.InternalConfigureFromXml(log4net.Repository.ILoggerRepository
 repository, System.Xml.XmlElement element)     Unknown
        
log4net.dll!log4net.Config.XmlConfigurator.InternalConfigure(log4net.Repository.ILoggerRepository
 repository, System.IO.Stream configStream)    Unknown
        
log4net.dll!log4net.Config.XmlConfigurator.InternalConfigure(log4net.Repository.ILoggerRepository
 repository, System.IO.FileInfo configFile)    Unknown
        
log4net.dll!log4net.Config.XmlConfigurator.InternalConfigureAndWatch(log4net.Repository.ILoggerRepository
 repository, System.IO.FileInfo configFile)    Unknown
        
log4net.dll!log4net.Config.XmlConfigurator.ConfigureAndWatch(System.IO.FileInfo 
configFile)     Unknown
   >    Log4NetTest_332.dll!Log4NetTest_332.Program.Main(string[] args) Line 15 
C#
   ```
   
   Attached is a sample project, containing the same client code for 3.4.0 and 
3.3.2:
   
   
[Log4NetTest.zip](https://github.com/user-attachments/files/32755636/Log4NetTest.zip)
   
   
   I did not find anything about this change in the release notes, and at first 
glance I did not see the change which caused this.
   
   So, first question is: is this change intentional or some kind of 
regression😄 ?
   
   If it is intentional, I probably would have to catch this kind of error and 
handle it somehow.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to