.NET - Exception Logging & Monitoring
What's the best way to monitor exception logging in production environment? I have an application where in exceptions are logged to a text file. Everytime, i need access to these log files, i got to request backoffice team to send me a copy.
To improvise this process, i have thought of few options:
1) Email the error logs on a开发者_StackOverflow社区 regular basis
2) Store the log file in database
3) Create some sort of listener objects to monitor logs (is this even possible?)
Is there a better option & how to implement one?
TIA
You should try Error Logging Modules And Handlers (ELMAH).
ELMAH is a free, opensource error logging library. It include features like:
- Error filtering
- View errors on a webpage (configurable user roles)
- RSS feed
- Download as CSV file
- Programmatically raise exception directly to it
- Notifications through email
For information on how to install and use check its page.
Further Reading
For more information on the topics discussed in this tutorial, refer to the following resources:
- ELMAH - Error Logging Modules and Handlers
- ELMAH Project Page (source code, samples, wiki)
- Plugging ELMAH Into a Web Application to Catch Unhandled Exceptions (video)
- Security Error Log Pages
- Using HTTP Modules and Handlers to Create Pluggable ASP.NET Components
- Website Security Tutorials
I highly recommend log4net
. You can do just about any type of logging with it, and plus, there's even an SMPTAppender example on the documentation page, found here. So you could actually mail the exceptions directly to whomever you'd like, you could store them in the DB, the possibilities are really endless.
Elmah and log4net are great solutions, especially if you need to store log & exception data on premise. They still require you to setup email accounts, or login somewhere to get securely stored logs.
Another option -- if your data can be stored in the cloud -- are hosted exception monitoring services like Appfail and Airbrake. These are cloud-based exception monitoring services.
For example, with Appfail you plug in a reporting module (similar to ELMAH's reporting module) which will report exceptions to its web service. You can then login to view analytics of failures and register to receive notifications about important failures.
** Disclaimer: I work on Appfail :-)
I'm sure your back office team could set up access directly to the logs, if you have a quick talk about how to do that securely.
Personally, I log tons of stuff out to log files because all sorts of information can be useful for a tricky situation. But I also log exceptions direct to the database and display them on a secure page so I can use that as a start point.
You might consider Seq - it's a server you can install in your own environment (MSI setup) then send logs to using NLog, log4net, or Serilog.
Once your apps are sending logs to Seq, you can query them using a web interface or configure handlers that notify you, perhaps by email but really any way you choose: handlers can be written in C# and plugged in.
I work on both products, so obviously not an impartial opinion, but after many years of using log4net and text files, the leap to centralized logging and fully-structured events is a pretty huge step forwards.
Serilog's open source (Apache2 on GitHub) and supports a variety of back-ends and output formats. Seq is commercial, but offers a very usable free edition.
精彩评论