[Mono-list] Nothing happens with mono-service and EventLog.WriteEntry

Michael Schurter michael at susens-schurter.com
Thu Feb 15 12:07:30 EST 2007


On Thu, 2007-02-15 at 10:52 -0500, Will Murnane wrote:
> On 2/15/07, Michael Schurter <michael at susens-schurter.com> wrote:
> > private void SmartLog (string message)
> > {
> >         int p = (int) Environment.OSVersion.Platform;
> >         if ((p == 4) || (p == 128)) {
> >                 // UNIX - Use Syslog
> >                 Mono.Unix.Native.Syscall.syslog (
> >                         Mono.Unix.Native.SyslogLevel.LOG_INFO,
> >                         message);
> >                 } else {
> >                         // Windows - Use EventLog
> >                         EventLog.WriteEntry (message);
> >                 }
> >         }
> > }
> A 2005 posting on this list suggested inverting the test, which makes
> the Magic Numbers go away:
> 	using System;
> 
> 	PlatformID id = Environment.OSVersion.Platform;
> 	if(   id == PlatformID.Win32NT
> 	   || id == PlatformID.Win32S
> 	   || id == PlatformID.Win32Windows
> 	   || id == PlatformID.WinCE)
> 	{
> 	    Console.WriteLine ("NOT running on Unix");
> 	}
> 	else
> 	{
> 	    Console.WriteLine ("Running on Unix");
> 	}
> 
> This is probably still working, but I haven't tried it.  Your mileage may vary.

This one seems to work.  I got it from the FAQ:

http://www.mono-project.com/FAQ:_Technical#How_to_detect_the_execution_platform_.3F

I would assume the one you posted is fine as well.



More information about the Mono-list mailing list