[Mono-devel-list] System.Diagnostic.EventLog

Jonathan Pryor jonpryor at vt.edu
Sat Oct 2 09:50:14 EDT 2004


On Fri, 2004-10-01 at 06:01, Robert Brown wrote:
> J-
>   I did a google search on mono and syslog and found a quick example
> [http://www.mail-archive.com/mono-list@lists.ximian.com/msg10313.html]. 
> Between what you listed below and the webpage that google pulled up
> should get me started.

It's nice to know that my examples can be useful. :-)

One word of note (as I re-read my earlier message): the Level
enumeration really shouldn't have a [Flags] attribute, as its values
can't be bitwise-ORed together.

<snip/>

> >         [DllImport("libc"
> >         static extern void syslog(int priority, string format, params
> > string[] args);

This is also an incredibly bad idea.  The reason being that syslog(3) is
prototyped as:

	void syslog (int priority, const char *format, ...);

A C# params array isn't going to be properly translated into a C varargs
argument ("..."), as a params array is still just an array (with
additional "syntactic sugar" for callers), and the array will be
marshaled as a single argument.

It would be better to stick with my original DllImport declaration:

	[DllImport("libc")]
	public static extern void syslog (int priority, string message);

Though, to be *really* safe, this would be better:

	[DllImport("libc")]
	private static extern void sys_syslog (int priority, 
		string message);

	public static void syslog (int priority, string message)
	{
		message = message.Replace ("%", "%%");
		sys_syslog (priority, message);
	}

This way, syslog(3) won't ever see formattable parameters that would be
passed on the stack (which is good, as *no* parameters will be passed on
the stack after "message", so this avoids reading garbage).

 - Jon




More information about the Mono-devel-list mailing list