Greetings,

I have been using log4net for a while and I think it rocks! It has allowed
me to focus on the business functionality and have provided a very reliable
and elegant platform for logging. So thanks to the people who maintain it. 

I have been trying all day to get the remote appender to work. I have looked
for examples but didn't find anything other than going into the source code
and checking out the unit tests. 

Here is my client class:

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;

using log4net.Core;
using IRemoteLoggingSink =
log4net.Appender.RemotingAppender.IRemoteLoggingSink;

namespace Miner.Responder.MultiSpeakInterfaces.Common
{
    public class RemoteLoggingSinkImpl : MarshalByRefObject,
IRemoteLoggingSink
        {
                        public static readonly RemoteLoggingSinkImpl Instance = 
new
RemoteLoggingSinkImpl();
                        public LoggingEvent[] Events = null;
            private TcpChannel m_remotingChannel;

                        #region Public Instance Constructors
                        private RemoteLoggingSinkImpl()
                        {
                        }

                        #endregion Public Instance Constructors

            public void RegisterRemotingServerChannel()
                    {
                            if (m_remotingChannel == null)
                            {
                                    m_remotingChannel = new TcpChannel(8085);

                                    // Setup remoting server
                                    try
                                    {
                                            
ChannelServices.RegisterChannel(m_remotingChannel);
                                    }
                                    catch(Exception)
                                    {
                                    }

                                    // Marshal the sink object
                                    
RemotingServices.Marshal(RemoteLoggingSinkImpl.Instance,
"LoggingSink", typeof(IRemoteLoggingSink));
                            }
                }
                        #region Implementation of IRemoteLoggingSink

                        /// <summary>
                        /// Logs the events to the repository.
                        /// </summary>
                        /// The events to log.
                        /// <remarks>
                        /// The events passed are logged to the <see 
cref="LoggerRepository"/>
                        /// </remarks>
                        public void LogEvents(LoggingEvent[] events)
                        {
                                Events = events;
                        }

                        #endregion Implementation of IRemoteLoggingSink

                        #region Override implementation of MarshalByRefObject

                        /// <summary>
                        /// Obtains a lifetime service object to control the 
lifetime 
                        /// policy for this instance.
                        /// </summary>
                        /// <returns>
                        /// <c>null</c> to indicate that this instance should 
live
                        /// forever.
                        /// </returns>
                        public override object InitializeLifetimeService()
                        {
                                return null;
                        }

                        #endregion Override implementation of MarshalByRefObject
                }
}


Pretty simple, correct?

My server is also very simple. Here is the configuration:

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

  <configSections>
    <section name="log4net" type="System.Configuration.IgnoreSectionHandler"
/>
  </configSections>
  <log4net>
    <root>
      <level value="ERROR" />
      <appender-ref ref="EventLogAppender" />
      <appender-ref ref="FileAppender" />
      <appender-ref ref="RemotingAppender"/>
      <level value="INFO"/>
      <appender-ref ref="FileAppender" />
      <appender-ref ref="RemotingAppender"/>
    </root>

    <appender name="TraceAppender" type="log4net.Appender.TraceAppender">
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern
           value="%date [%thread] %-5level %logger [%property{NDC}] -
%message%newline" />
      </layout>
    </appender>

    <appender name="ConsoleAppender"
type="log4net.Appender.ConsoleAppender">
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern
           value="%date [%thread] %-5level %logger [%property{NDC}] -
%message%newline" />
      </layout>
    </appender>

    <appender name="FileAppender" type="log4net.Appender.FileAppender">
      <file value="c:\\Log\\log-file.txt" />
      <appendToFile value="true" />
      <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern
           value="%date [%thread] %-5level %logger [%property{NDC}] -
%message%newline" />
      </layout>
    </appender>

    <appender name="EventLogAppender"
type="log4net.Appender.EventLogAppender" >
      <applicationName value="Test Service" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger
[%property{NDC}] - %message%newline" />
      </layout>
    </appender>

    <appender name="RemotingAppender"
type="log4net.Appender.RemotingAppender" >
      <sink value="tcp://localhost:8085/LoggingSink" />
      <lossy value="false" />
      <bufferSize value="95" />
      <onlyFixPartialEventData value="true" />
    </appender>



  </log4net>

</configuration>

and my server code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        private static readonly log4net.ILog _log =
log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            while (true)
            {
                _log.Info(DateTime.Now.ToLongTimeString());
                Thread.Sleep(1000 * 10);
            }
        }
    }
}


I can see the remoting listener start but a connection is never made. The
server is generating the messages, I can see then on the event log. Any
ideas?

Cheers,

PP

-- 
View this message in context: 
http://www.nabble.com/Remote-Appender-tp23605546p23605546.html
Sent from the Log4net - Users mailing list archive at Nabble.com.

Reply via email to