spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / programming / asp / logging To page 1To page 2To page 3To page 4current pageTo page 6
[previous] [next]

Event Logging in .NET

C/C++ Developer (NYC)
Next Step Systems
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume
Developer News
Eclipse Helios Update Brings New PHP Tools
Internet Explorer 9 Ups Standards Support
JBoss Portal 5 Release Easier to Use


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();
      }
   }
}

home / programming / asp / logging To page 1To page 2To page 3To page 4current pageTo page 6
[previous] [next]

webref The latest from WebReference.com Browse >
Flashmaps' DynamicLocator: Interactive Maps for Small Areas · Flashmaps' AreaSelector: Interactive Maps for Wide Areas · The DB Mapper: Interactive Street-level Maps of U.S. and Canada
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
MS Access and MySQL · Cisco AutoQoS: VoIP QoS for Mere Mortals · While VoIP Adoption Explodes in Enterprise, Carrier Spending Lags

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

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