[Mono-list] Mono and EventLog

Zsolt Molnar zs-molnar at alpine.hu
Thu Feb 15 02:20:36 EST 2007


Hi All,

Could anybody give advice how to manage the EvenLogs of  Windows computers 
and servers from Mono under Linux ??
Here is a sample code which works fine under Windows but nothing happen 
when I run under Linux and I don't get any error message.
Of course I tried the machine name with Windows machine's IP address.

using System;
using System.Text;
using System.Diagnostics;

    class Program
    {
        static void Main()
        {
            string myRemoteMachine;
            string myLogName = "MyLog";

            Console.Write("Enter computer on which to create log : ");
            myRemoteMachine = Console.ReadLine();

            // Check if the source exists.
            if (!EventLog.SourceExists("MyTestSource"))
            {
                //Create source.
                EventLog.CreateEventSource("MyTestSource", myLogName, 
myRemoteMachine);
                Console.WriteLine("Creating EventSource");
            }
            else
                // Get the EventLog associated if the source exists.
                myLogName = EventLog.LogNameFromSourceName("MyTestSource", 
myRemoteMachine);

            EventLog myEventLog1 = new EventLog(myLogName, 
myRemoteMachine);
            myEventLog1.Source = "MyTestSource";
            // Write an entry into log.
            myEventLog1.WriteEntry("This is for your information",
                                           EventLogEntryType.SuccessAudit, 
100);
            Console.WriteLine("An EventLog created on computer " +
                                           myEventLog1.MachineName);

            Console.Write("Enter remote computer on which to create log : 
");
            myRemoteMachine = Console.ReadLine();

            EventLog myEventLog2 = new EventLog();
            myEventLog2.MachineName = myRemoteMachine;
            myEventLog2.Source = "MyTestSource";
            myEventLog2.Log = myEventLog1.LogDisplayName;
            myEventLog2.WriteEntry("This is for your information");
            Console.WriteLine("An EventLog created on computer " +
                                               myEventLog2.MachineName);


        }
    }

Best Regards,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-list/attachments/20070215/d3c0c349/attachment.html 


More information about the Mono-list mailing list