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

Robert Jordan robertj at gmx.net
Thu Feb 15 12:09:48 EST 2007


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 test is not valid because future OS platforms (say
Win64<InsertCoolNameHere>) would be mapped to Unix.

Robert



More information about the Mono-list mailing list