Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# TCP/IP log4net Append Remoting , +
Hello
 
I provided a C# application, which to log messages over a TCP/IP connection to a CONSOLE (a TXT file would also go) to transfer and indicate is. Unfortunately this does not function and I didn't know which changes is necessarily thereby the messages over the TCP/IP connection can be transferred. Logging the messages in a local TXT file functions.I have the following Config (app.config) in my monitor application:
 
<?xml version="1.0"?>
<configuration>
  <system.runtime.remoting>
    <application>
      <channels>
        <channel ref="tcp" port="8086"/>
      </channels>
    </application>
  </system.runtime.remoting>
</configuration>
 
I have in my monitor application Program.cs and RemoteSink.cs the following
source code. Here is the file Program.cs:
 
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Remoting;
 
namespace Monitor
{
    class Program
    {
        static void Main(string[] args)
        {
            RemotingConfiguration.Configure("Monitor.exe.config", false);
            RemotingConfiguration.RegisterWellKnownServiceType(new WellKnownServiceTypeEntry(typeof(RemoteSink), "LoggingSink", WellKnownObjectMode.SingleCall));
 
            Console.WriteLine("Monitor started");
            Console.WriteLine("Press <ENTER> to kill.");
            Console.WriteLine();
            Console.ReadLine();
        }
    }
}
 
And here is the file RemoteSink.cs
 
using System;
using System.Collections.Generic;
using System.Text;
using log4net.Appender;
using log4net.Core;
 
namespace Monitor
{
    public class RemoteSink : MarshalByRefObject, RemotingAppender.IRemoteLoggingSink
    {
        public void LogEvents(LoggingEvent[] events)
        {
            foreach (var loggingEvent in events)
            {
                // %date [%thread] %-5level %logger - %message %newline
                Console.WriteLine("{0} [{1}] {2} {3} - {4}", loggingEvent.TimeStamp.ToLongTimeString(), loggingEvent.ThreadName, loggingEvent.Level.Name, loggingEvent.LoggerName, loggingEvent.RenderedMessage);
            }
        }
    }
}
 

And the following config (app.config) in my main-application:
 
<?xml version="1.0"?>
<configuration>
  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" requirePermission="false" />
  </configSections>
 
  <log4net>
    <appender name="FileAppender" type="log4net.Appender.FileAppender">
      <threshold value="DEBUG"/>
      <file value="V:\\Logs\\log.txt" />
      <appendToFile value="true" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger - %message %newline" />
      </layout>
    </appender>
    <appender name="RemotingAppender" type="log4net.Appender.RemotingAppender" >
      <bufferSize value="2" />
      <sink value="tcp://localhost:8086/LoggingSink" />
      <lossy value="false" />
      <onlyFixPartialEventData value="true" />
    </appender>
    <appender name="BufferRemotingAppender" type="log4net.Appender.BufferingForwardingAppender" >
      <bufferSize value="2" />
      <evaluator type="log4net.Core.LevelEvaluator">
        <threshold value="DEBUG"/>
      </evaluator>
      <appender-ref ref="RemotingAppender" />
    </appender>
    <root>
      <level value="ALL" />
      <appender-ref ref="FileAppender" />
      <appender-ref ref="BufferRemotingAppender" />
    </root>
  </log4net>
</configuration>
 
My main-application is a Windows-Form, and has the following source-code:
 
using System;
using System.Reflection;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using log4net;
using log4net.Config;
 
//[assembly: log4net.Config.XmlConfigurator(Watch = true)]
 
namespace WinAppWithLogging
{
    public partial class Form1 : Form
    {
        //private static readonly ILog log = LogManager.GetLogger(typeof(Form1));
        private static readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
 
        public Form1()
        {
            InitializeComponent();
        }
 

 
        private void button1_Click(object sender, EventArgs e)
        {
            log4net.Config.XmlConfigurator.Configure();
            log.Warn("my TCP info");
        }
    }
}
--
 
Mfg
Dominique
Posted 18-Dec-12 22:43pm
Comments
jibesh at 19-Dec-12 6:56am
   
I dont see any code that instantiate the class 'RemoteSink' in your button click you are just using the Log4Net lib and not the remoting server instance.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Read about .Net Remoting here
a-simple-remoting-example-in-c/[^]
dotnetremoting[^]
  Permalink  
Comments
Dominique Krug at 9-Jan-13 5:24am
   
thanks for your help but the 'monitor' and the 'RemoteSink' is the host application. The class 'program' has the line: RemotingConfiguration.RegisterWellKnownServiceType(new WellKnownServiceTypeEntry(typeof(RemoteSink), "LoggingSink", WellKnownObjectMode.SingleCall));
in order the 'RemoteSink' admits to make.
The main-application is the client and should run on a different system.
Perhaps i must add or change a line in the xml configuration?
 
Dominique

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 195
1 ProgramFOX 130
2 Maciej Los 105
3 Sergey Alexandrovich Kryukov 105
4 Afzaal Ahmad Zeeshan 82
0 OriginalGriff 6,564
1 Sergey Alexandrovich Kryukov 6,048
2 DamithSL 5,228
3 Manas Bhardwaj 4,717
4 Maciej Los 4,150


Advertise | Privacy | Mobile
Web02 | 2.8.1411022.1 | Last Updated 19 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100