syslog equivalent

I have a c++ program that runs on unix, but is pretty platform independent, and I do have a console version running on Windows. I am trying to move it into a Windows web environment. I don't really know the innards of how the web bit works, but I know it is supposed to:

1) Prepare appropriate i/o directories for me
2) Set an environment variable pointing to those directories
3) Launch the executable.

Once I have confirmed that the directories are set up correctly I can then log any errors to an appropriate file. What I'm unsure about is how to log any errors with finding those directories or if they are not set up correctly.

The user the executable is launched as only has write access in the directory that is specified by the environment variable. So if there is a problem with this I can't write anywhere. The server is a headless, so MessageBox isn't really the ideal solution.

On unix I would just call syslog() but I can't find the simple equivalent on Windows. I found the Event API, but it looked terribly complicated. Is there a one line solution, for someone who doesn't want to learn half of the Windows API?

Thanks,
Kevin
Error logging in Windows is done in Event Viewer like you saw. Here's a pretty useful article I found on it, but if you're new to Win32 then you may need more research so post back here and we'll help you out: http://support.microsoft.com/kb/815661

Other options would include dumping a text file to anywhere in the users profile directory, they normally have write permissions there. This is normally:

Windows XP: %SYSTEMDRIVE%\Documents and Settings\USERNAME

Vista and 7: %SYSTEMDRIVE%\Users\USERNAME

It's because of things like this that there is a need for things like Event Viewer, as a bonus however Windows System Admins will love your software since MMC allows them to access the error remotley at a fixed location.

EDIT: The one liner that you were looking for by the way is "EVENTCREATE" and is a command line command not an API function. It also requires Administrator rights so you're back to the issue with the user who is running the software not having permissions. http://ss64.com/nt/eventcreate.html
Last edited on
That article was much simpler than what I managed to find on msdn. I've basically copied it into a static library with a few modifications, and exported a plain c function that resembles syslog. I've checked that I can link to it from a win32 console application and I can. So I'll just use a #ifdef _WIN32 in my main code tree to decide which function to call, and that way the main tree stays relatively simple, and platform independent.

Thanks,
Kevin
Topic archived. No new replies allowed.