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

Sr Instructional Designer D2L-Moodle,Clearance
WSI Nationwide, Inc.
US-NJ-Fort Monmouth

Justtechjobs.com Post A Job | Post A Resume
Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs


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]

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint

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

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