logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Thorne-Smith, Benjamin" <btsm...@zygo.com>
Subject ArgumentNullException on log4Net.LogManager.Shutdown()
Date Thu, 19 Apr 2007 17:38:54 GMT
Hello, I am new to log4net and am looking for some advice on how to
avoid an exception.

 

I am trying to get the logging for several apps to the same log file
through your remoting appender. Everything works wonderfully until I
move to shutdown the LogManager. 

 

I initialize my LogManager as follows:

void Initialize()

{

System.Configuration.Configuration config =
System.Configuration.ConfigurationManager.OpenExeConfiguration(System.Co
nfiguration.ConfigurationUserLevel.None);

if (config.HasFile)

{

log4net.Config.XmlConfigurator.Configure(new
System.IO.FileInfo(config.FilePath));

}

RemotingConfiguration.Configure(AppDomain.CurrentDomain.SetupInformation
.ConfigurationFile, false);

log4net.LogManager.GetRepository().PluginMap.Add(new
log4net.Plugin.RemoteLoggingServerPlugin("LoggingSink"));

}

 

The exception message is as follows:

System.ArgumentNullException was unhandled

         Message="Value cannot be null.\r\nParameter name: obj"

         Source="mscorlib"

         ParamName="obj"

         StackTrace:

              at
System.Runtime.Remoting.RemotingServices.Disconnect(MarshalByRefObject
obj, Boolean bResetURI)

              at
System.Runtime.Remoting.RemotingServices.Disconnect(MarshalByRefObject
obj)

              at log4net.Plugin.RemoteLoggingServerPlugin.Shutdown()

              at log4net.Repository.LoggerRepositorySkeleton.Shutdown()

              at log4net.Repository.Hierarchy.Hierarchy.Shutdown()

              at log4net.Core.LoggerManager.Shutdown()

              at log4net.LogManager.Shutdown()

 

I originally thought that I could elminate the error by shutting down
the repoistory, clearing the plugins and then calling the master
shutdown method(below). I had guessed that since there would be no
plugins in the plugin map so that
log4net.Plugin.RemoteLoggingServerPlugin.Shutdown() would not get
called. However the same exceptin still appears.

void Shutdown()
{

log4net.LogManager.ShutdownRepository();

log4net.LogManager.GetRepository().PluginMap.AllPlugins.Clear();

log4net.LogManager.Shutdown();

}

 

I poked my head into the source code and found I could quiet the
exception by changing the RemoteLoggingServerPlugin.Shutdown method like
this (below, changes in bold). However I would prefer to know what I
have misused to cause this exception rather than just ignoring it.

override public void Shutdown()

{

// Stops the sink from receiving messages

if (m_sink != null)

{

    RemotingServices.Disconnect(m_sink);

}

      m_sink = null;

      base.Shutdown();

}

 

I have included my example source code below and would greatly
appreciate any help anyone could give me. Thanks for your time,

 

Ben Smith

 

//The master application

[STAThread]

static void Main()

{

Application.EnableVisualStyles();

      Application.SetCompatibleTextRenderingDefault(false);

      ManagerWrapper.Initialize(); //code for this included above

      ProcessController.Instance.StartAllProcesses(); //launches the
service apps that will use the remote appender

      Application.Run(new Form1());

      ProcessController.Instance.KillAllProcessesSpawnedHere(); //kills
the service apps that used the remote appender

      ManagerWrapper.Shutdown(); //code for this included above

}

 

//code for the main app

public partial class Form1 : Form

{

private static readonly ILog log =
ManagerWrapper.GetLogger(typeof(Form1));

      public Form1()

      {

            InitializeComponent();

      }

 

      private void btnLog_Click(object sender, EventArgs e)

      {

            log.Info("App logging");

      }

}

 

//The app.config file for the master app

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

<configuration>

  <configSections>

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

  </configSections>

  <log4net>

    <appender name="BufferingMemoryAppender"
type="log4net.Ext.Zygo.Appender.BufferingMemoryAppender,
log4net.Ext.Zygo">

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

        <conversionPattern value="%d [%t] %-5p %c %x - %m%n"/>

      </layout>

      <maxEventCount value="5000"/>

    </appender>

    <appender name="SystemLogAppender"
type="log4net.Ext.Zygo.Appender.RollingFileAppender, log4net.Ext.Zygo">

      <level value="DEBUG"/>

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

      <appendToFile value="false"/>

      <rollingStyle value="Composite"/>

      <maximumFileSize value="5MB"/>

      <maxSizeRollBackups value="30"/>

      <staticLogFileName value="true"/>

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

        <conversionPattern value="%d [%t] %-5p [%c] - %m%n"/>

      </layout>

    </appender>

    <root>

      <level value="ALL"/>

      <appender-ref ref="BufferingMemoryAppender"/>

      <appender-ref ref="SystemLogAppender"/>

    </root>

  </log4net>

  <system.runtime.remoting>

    <application name="MetroProXP">

      <channels>

        <channel displayName="Server Channel" ref="tcp server"
port="8085" />

      </channels>

    </application>

  </system.runtime.remoting>

</configuration>

 

//An example of a service application

/// <summary>

/// The main entry point for the application.

/// </summary>

[STAThread]

static void Main()

{

      Application.EnableVisualStyles();

      Application.SetCompatibleTextRenderingDefault(false);

      ManagerWrapper.Initialize(); //code for this included above

      Application.Run(new Form1());

      ManagerWrapper.Shutdown(); //code for this included above

}

 

//code for a service app

public partial class Form1 : Form

{

private static readonly ILog log =
ManagerWrapper.GetLogger(typeof(Form1));

      public Form1()

      {

            InitializeComponent();

      }

 

      private void btnLog_Click(object sender, EventArgs e)

      {

            log.Info("Service App logging");

      }

}

 

//The app.config file for the service app

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

<configuration>

  <configSections>

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

  </configSections>

  <log4net debug="false">

    <appender name="RemotingAppender"
type="log4net.Appender.RemotingAppender" >

      <sink value="tcp://localhost:8085/LoggingSink" />

      <lossy value="false" />

      <bufferSize value="1" />

      <onlyFixPartialEventData value="true" />

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

        <conversionPattern value="%d [%t] %-5p %c %x - %m%n"/>

      </layout>

    </appender>

    <root>

      <level value="ALL" />

      <appender-ref ref="RemotingAppender" />

    </root>

  </log4net>

  <appSettings>

    <add key="log4net.Internal.Debug" value="true"/>

  </appSettings>

</configuration>

 

The ManagerWrapper class is just a wrapper around the log4net.LogManager
with some additional functionality.

 


Mime
View raw message