Monday, May 2, 2011

log4net: No appenders could be found for logger

This is my initial foray into Log4Net for use with my WCF service. Since Log4Net is configuration based, if you do not see anything logged to your destination (in my case it is a database) then you have missed something in your config (that should not be any surprise, my point is to reinforce the reader to double check their config settings). In my particular case I am using the AdoNetAppender. I configured my database, installed and referenced the Log4net dll's and set about to log my first exception. After messing with it for a couple of hours I realized that I was missing the <appender-ref ref="AdoNetAppender" /> key in my config. The exception that was being thrown by Log4Net was

log4net: Logger: No appenders could be found for logger [PSLogger, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null] repository [log4net-default-repository]
log4net: Logger: Please initialize the log4net system properly.
log4net: Logger:    Current AppDomain context information:
log4net: Logger:       BaseDirectory   : C:\$\1.0\PSAuditService\PSAuditService\
log4net: Logger:       FriendlyName    : dbd5742-18-129488220968600299
log4net: Logger:       DynamicDirectory: C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\ec718ec8\d90fe912

After adding the afore mentioned key all seems to be well.

Hope this helps someone.

3 comments:

  1. I have a very similar problem with a simple Windows application (proff202a.exe) invoked by another application.
    I read over the referenc material and could not find what I am doing wrong. The debug logs I get are the following.
    If you could provide any clues it would be much appreciated. Thanks.

    log4net: XmlHierarchyConfigurator: Configuration update mode [Merge].
    log4net: XmlHierarchyConfigurator: Hierarchy Threshold []
    log4net: XmlConfigurator: configuring repository [log4net-default-repository] using .config file section
    log4net: XmlConfigurator: Application config file is [C:\proff\profft2202a.exe.config]
    log4net: XmlConfigurator: Configuring Repository [log4net-default-repository]
    log4net: XmlHierarchyConfigurator: Configuration update mode [Merge].
    log4net: XmlHierarchyConfigurator: Hierarchy Threshold []
    log4net: Logger: No appenders could be found for logger [ProffT2202A.EntryPoint] repository [log4net-default-repository]
    log4net: Logger: Please initialize the log4net system properly.
    log4net: Logger: Current AppDomain context information:
    log4net: Logger: BaseDirectory : C:\proff\
    log4net: Logger: FriendlyName : profft2202a.exe
    log4net: Logger: DynamicDirectory:
    log4net: DefaultRepositorySelector: Creating repository for assembly [proffpdf, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]
    log4net: DefaultRepositorySelector: Assembly [proffpdf, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null] Loaded From [C:\proff\proffpdf.dll]
    log4net: DefaultRepositorySelector: Assembly [proffpdf, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null] does not have a RepositoryAttribute specified.
    log4net: DefaultRepositorySelector: Assembly [proffpdf, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null] using repository [log4net-default-repository] and repository type [log4net.Repository.Hierarchy.Hierarchy]
    log4net: DefaultRepositorySelector: repository [log4net-default-repository] already exists, using repository type [log4net.Repository.Hierarchy.Hierarchy]
    log4net: Hierarchy: Shutdown called on Hierarchy [log4net-default-repository

    ReplyDelete
  2. What appender are you using? File or AdoNet?

    Make sure you are referencing the named appender in your log4net config. I am providing a working config for the AdoNetAppender....tweak to suit your needs.
















































    Hopefully this helps. Let me know if this worked for you

    ReplyDelete
  3. For some reason I cannot paste my config here. If you still haven't solved your issue, please email me and I will send you a working config.

    ReplyDelete