简体   繁体   中英

Windows Service: Where to write log messages (EventLog, File or DB Table) / Access from Web

We have a windows service (in .NET) that will write a fair amount of messages to a log.

This log is of interest not only to server administrators but also to normal clients who use a web page to access the system. Or to us trying to remote debug the system!

We are considering using the normal windows server event log, or writing to a Database table or maybe just old-skool writing to a file.

Does anyone have any best practise advice on which to use?

Important is really only that the log is available to view in the web page, for which purpose I imagine the DB table being the easiest method to accomplish this? How easy would it be to show the windows event log via the web (assuming we only filter for messages which are relevant to our app?)

As you've stated that the log needs to be accessible via a web page, the best place to store the information would almost certainly be in the database as you can use code that you're familiar with to retrieve records to present in the web interface.

That said, if you're building an "enterprise" system, you might want to consider the fact that monitoring solutions such as Big Brother have facilities built in to watch for event log entries and react to them, so some form of logging to the Event Log would be valuable for system administrators in that situation. Also, Windows offers " Event Log Forwarding " which allows event log entries from multiple machines to be aggregated for review on a single machine. Possibly not relevant in your scenario, but worth bearing in mind.

Try to think about ease of implementing. You already have the whole infrastructure to work with DB. It should be easy to just add new stored procedure or query. You can easy have a backup. And also, you can easy transfer this DB to another server if you need. Windows server event log is a good place too, but backups, portability and performance can suffer. If you have a dedicated DB server then it is a better choice, IMHO

If you use something like Enterprise Library logging its pretty trivial to have one message get logged to multiple locations. It also pretty easy to extend it and write your own formats and targets. You can even get out of process logging with it. Another nice aspect of this is that if one of the locations is broken (eg DB is down or the file is locked) you have the event log that will log those errors.

Also it should be noted that your local event viewer can Connect to another Computer . Administrators usually don't have a problem granting devs read access to it. Another plus to event viewer is that if you use LogParser you can query it.

Eventlog is a better place for logging. You can view log records in Event Viewer and access these records programmatically.

I don't advise you to use an ordinary file. It's simple but not manageable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM