Home Downloads Buy Now !

 Errored Events

 

This sample demonstrates using the error message support. It demonstrates how to send messages from various sources and how to set up and handle the Errored events. Using the Windows Event Log is also demonstrated.

 

using System;

using IDN.IO;

  

namespace Error_Message_Example

{

    class Class1

    {

        [STAThread]

        static void Main(string[] args)

        {

            // Create the tag server.

            TagServer tagServer = new TagServer();

  

            // Subscribe to all error events.

            tagServer.Errored += new ErroredDelegate(OnIOErroredEventHandler);

         

            // Create an IONode and add it to the TagServer.

            IONode node = new IONode();

            node.NodeName = Environment.MachineName;

            node.Name = "MyNode";

            tagServer.AddChild(node);

  

            // Set your preferences for the windows event logger.

            // Set them at any time or use the defaults.

            tagServer.LogSourceName        = ("MyApplicationName");

            tagServer.EnableErrorLog       = true; // default

            tagServer.EnableWarningLog     = true; // default

            tagServer.EnableInformationLog = false;

          

            tagServer.Error(null,       "Send an error message.         ");

            tagServer.Warning(null,     "Send a warning message.        ");

            tagServer.Information(node, "Use a different source object. ");

  

            // Send via the node as all IDNBrowsable's have error methods.

            node.Error(node,            "This goes to the event logger. ");

            node.Information(node,      "This doesn't go to the logger. ");

  

            tagServer.Release();

            Console.WriteLine("Done... [Enter] to exit.");

            Console.ReadLine();

        }

  

        // Receive all messages from the tag server.

        static void OnIOErroredEventHandler(object sender, IDN.IO.ErroredEventArgs e)

        {

            // If it is an IDNBrowsable we can display the instance name.

            if ((e.Sender != null) && (e.Sender.GetType().IsSubclassOf(typeof(IDNBrowsable))))

            {

                Console.WriteLine(e.Message+e.Severity.ToString()+": "+e.Timestamp.ToString()+": "+((IDNBrowsable) e.Sender).Name);

            }

            else

                // Not an IDNBrowsable so it could be from a form or other object.

                Console.WriteLine(e.Message+e.Severity.ToString()+": "+e.Timestamp.ToString());

        }

    }

}

 



Copyright © 2004-2017 Industrial DOT NET, Inc.