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 "Dahl, Scott (CMA Consulting)" <sd...@cma.com> on 2007/04/17 23:55:08 UTC

Cannot create log from vb.net class library .dll

I have created a web service and web service client that both utilize
log4net nicely.  The service side utilizes a class library .dll which
I've also attempted to use log4net for logging.  I have been unable to
create a log or write to the referring web service log from the class
library yet.  

 

Here's a stripped down version of the current class library dll code:

 

Imports System.IO

 

' We want this assembly to have a seperate logging repository to the 

' rest of the application. We will configure this repository seperatly.

'<Assembly:
log4net.Config.AliasRepository("trafficRouter.trafficRouter")> 

'<Assembly: log4net.Config.XmlConfigurator(Watch:=True)> 

 

Public Class trafficRouter

    Private db As New dbConnection

    ' Create a logger for use in this class

    Private Shared ReadOnly l As log4net.ILog =
log4net.LogManager.GetLogger("default")

 

    Public Sub New()

        Try

            log4net.Config.XmlConfigurator.Configure()

            'log4net.Config.XmlConfigurator.ConfigureAndWatch(New
FileInfo("c:\\ xyz.config"))

            l.Info("Creating Traffic Router.")

            dbConnect()

            l.Info("Done creating Traffic Router.")

        Catch ex As Exception

            l.Error(ex)

        End Try

    End Sub

End Class

 

This is the web.config file for the web service which is logging
correctly:

<?xml version="1.0"?>

<configuration
xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">

    <configSections>

        <section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler" />

    </configSections>

    <appSettings/>

    <!-- This section contains the log4net configuration settings -->

    <log4net>

      <!-- Define some output appenders -->

      <appender name="LogFileAppender"
type="log4net.Appender.FileAppender">

        <file value=".\\GenericInterface.log" />

        <appendToFile value="true" />

        <layout type="log4net.Layout.PatternLayout">

          <conversionPattern value="%date [%thread] %-5level %logger -
%message%newline" />

        </layout>

      </appender>

 

      <logger name="default">

        <level value="ALL" />

        <appender-ref ref="LogFileAppender" />

      </logger>

    </log4net>  

    <connectionStrings/>

    <system.web>

        <compilation debug="false" />

        <authentication mode="Windows" />

    </system.web>

</configuration>

 

Here is the "custom config" I tried using for the class library log:

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

    <system.diagnostics>

        <sources>

            <!-- This section defines the logging configuration for
My.Application.Log -->

            <source name="DefaultSource" switchName="DefaultSwitch">

            </source>

        </sources>

        <switches>

            <add name="DefaultSwitch" value="Information" />

        </switches>

    </system.diagnostics>

  

  <!-- Register a section handler for the log4net section -->

  <configSections>

      <section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />

  </configSections>

  <!-- This section contains the log4net configuration settings -->

    <log4net>

      <!-- Define some output appenders -->

      <appender name="LogFileAppender"
type="log4net.Appender.FileAppender">

        <file value=".\\trafficRouter.log" />

        <appendToFile value="true" />

        <layout type="log4net.Layout.PatternLayout">

          <conversionPattern value="%date [%thread] %-5level %logger -
%message%newline" />

        </layout>

      </appender>

 

      <logger name="default">

        <level value="ALL" />

        <appender-ref ref="LogFileAppender" />

      </logger>

    </log4net>

</configuration>

 

I've come across a few suggestions but none of those have helped at all.
This is what I've tried different from the current code:

1)       Explicitly call the
log4net.Config.XmlConfigurator.ConfigureAndWatch function, passing my
custom configuration above, in the constructor.

2)       Setting an alias repository using: Assembly:
log4net.Config.AliasRepository("trafficRouter.trafficRouter")> and
Assembly: log4net.Config.AliasRepository("trafficRouter")>

3)       Uncommenting the other assembly line from the class.

 

I'm pretty new to .net and log4net so please excuse me if I've stumbled
with some terminology or overlooked the obvious.   

 

Thanks,

Scott