Event Logging and Distributed Logging in ASP.NET (5/6) | WebReference

Event Logging and Distributed Logging in ASP.NET (5/6)

To page 1To page 2To page 3To page 4current pageTo page 6
[previous] [next]

Event Logging in .NET

Now we are ready to test our library. We wrap it all in a namespace Devents and compile it into a dll (and optionally register it with the GAC). The client code is as follows. All it does is create a bunch of events and logs them with LocalLog.

using System;
using System.Configuration;
using System.Collections;
using DEvents;
namespace DEvents
{
   public class Client
   {
      public static void Main(string[] args)
      {
         IDictionary config = (IDictionary) 
                              ConfigurationSettings.GetConfig("GlobalLog");         
         LocalEventLog.Init((string)config["url"]);
         string[] inserts = {"Insert 1", "Insert 2"};
         for(int i = 0; i < 100; i ++)
         {
            LocalEventLog.Instance.LogEvent(es,new Event(i,inserts));
         }                               
      }
   }
}

This implementation requires a config file since we do not want to hardcode the remote log's URL. The following config file can be used.

<configuration>
    <configSections>
        <section name="GlobalLog"
                    type="System.Configuration.SingleTagSectionHandler" />
    </configSections>
    <GlobalLog url="tcp://GlobalLog:8085/LogEvent" />
</configuration>

The server is equally simple. The only important thing is that the server is implemented as a singleton client. We use TCP as the protocol for remote communication. Obviously, HTTP can also be used, but TCP provides much better performance and it is fair to assume that the applications are all on a local LAN where TCP will not have any problems.

using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
namespace DEvents
{
   public class Server
   {
      public static void Main(string[] args)
      {
         TcpChannel chan = new TcpChannel(8085);
         ChannelServices.RegisterChannel(chan);
         RemotingConfiguration.RegisterWellKnownServiceType(
            typeof(DEvents.GlobalEventLog), "LogEvent",
            WellKnownObjectMode.Singleton);
         System.Console.WriteLine("Hit  to exit...");
         System.Console.ReadLine();
      }
   }
}

To page 1To page 2To page 3To page 4current pageTo page 6
[previous] [next]

Created: January 16, 2003
Revised: January 16, 2003

URL: http://webreference.com/programming/asp/logging/5.html