Create your log4net configuration file something like:
<log4net debug="true">
        <appender name="MyAppender" type="log4net.Appender.RemotingAppender"
>
                <param name="Sink"
value="tcp://localhost:11000/AppenderSink" />
                <param name="Lossy" value="false" />
                <param name="BufferSize" value="20" />
                <param name="OnlyFixPartialEventData" value="true" />
        </appender>
        <root>
                <level value="ALL" />
                <appender-ref ref="MyAppender" />
        </root>
</log4net>

Setup the remoting configuration application as follows:
  <system.runtime.remoting>
    <customErrors mode="off" />
    <application>
      <channels>
        <channel name="MySink" displayName="Server Channel" ref="tcp server"
port="11000" />
      </channels>
    </application>
  </system.runtime.remoting>

Here is the code to do your remoting:

// Configuration
RemotingConfiguration.Configure(
        AppDomain.CurrentDomain.SetupInformation.ConfigurationFile );

// Marshal the remoteable object
_remotedType = new RemoteType();
_remoteHandler = new RemoteEventHandler(RemoteTypeRemoted);
RemotingServices.Marshal( _remotedType, 
        "AppenderSink", 
        typeof(IRemoteLoggingSink) );

_remotedType.Remoted += _remoteHandler;

// Delegate to receive events
private void RemoteTypeRemoted(object sender, RemoteEventArgs remoteArgs)
{
        // Do Something with the event arguments here
}

// Remoteable object
[Serializable]
public class RemoteEventArgs : EventArgs
{
        private string _message = null;
        private string _context = null;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="messageIn"></param>
        /// <param name="contextIn"></param>
        public RemoteEventArgs( string messageIn, string contextIn )
        {
                this._message = messageIn;
                this._context = contextIn;
        }

        /// <summary>
        /// 
        /// </summary>
        public string Message
        {
                get { return _message; }
        }

        /// <summary>
        /// 
        /// </summary>
        public string Context
        {
                get { return _context; }
        }
}

/// <summary>
/// 
/// </summary>
public delegate void RemoteEventHandler( object sender, 
        
RemoteEventArgs remoteArgs );

/// <summary>
/// 
/// </summary>
public class RemoteType : MarshalByRefObject, 
        log4net.Appender.RemotingAppender.IRemoteLoggingSink
{
        /// <summary>
        /// 
        /// </summary>
        public RemoteType()
        {
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override object InitializeLifetimeService()
        {
                return null;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="events"></param>
        public void LogEvents( log4net.Core.LoggingEvent[] events )
        {
                if( Remoted != null )
                {
                        RemoteEventArgs args;
                        foreach( log4net.Core.LoggingEvent le in events )
                        {
                                args = new RemoteEventArgs(
le.RenderedMessage, le.NestedContext );
                                Remoted( this, args );
                        }
                }
        }

        /// <summary>
        /// 
        /// </summary>
        public event RemoteEventHandler Remoted;
}

-----Original Message-----
From: Michael Miller [mailto:[EMAIL PROTECTED]
Sent: Monday, June 14, 2004 2:53 PM
To: [email protected]
Subject: RemoteLoggingServerPlugin Info/Example


I want to create a remoting server to capture log information to file from
different processes using log4net with the remoting appender.  Does anyone
have a quick example or any helpful information on how use the
RemoteLoggingServerPlugin to do this?  The documentation mentions the
plugin, but I don't understand what to do with it -- any information would
be helpful. 
Thanks, 
Mike

Reply via email to