Reputation: 346
I have a C#.net site which displays custom error pages to the user. This is set in web.config:
<customErrors mode="Off">
<error statusCode="500" redirect="~/error.cshtml" />
<error statusCode="404" redirect="~/error.cshtml" />
</customErrors>
The problem is that if there is an error, I have no record of what it was. I'm familiar with PHP where I can set a location for the error_log file which I can then check for PHP errors. Is there a way to do something similar in .NET?
Upvotes: 0
Views: 627
Reputation: 19365
Have a look at the HealthMonitoring possibilities that come with ASP.Net. For instance, you can get references to exceptions and send emails with the exception to a specified address. A couple of years ago I wrote this article about HealthMonitoring: http://www.tomot.de/en-us/article/6/asp.net/how-to-create-a-custom-healthmonitoring-provider-that-sends-e-mails
If you want a more mature error logging solution, have a look at Elmah.
Upvotes: 0
Reputation: 544
You can use the built-in logging functionality that comes with ASP.NET.
Set it up in system.diagnostics in web.config, declare a trace source in your code and off you go.
You can configure it to write to the event log as well as log files and custom destinations.
I just did a quick google search and found an introductory article here: http://www.thejoyofcode.com/from_zero_to_logging_with_system_diagnostics_in_15_minutes.aspx
You will find many more without too much effort.
Upvotes: 0
Reputation: 350
You can use log4net dll, it has provisions to log errors as well as diagnostic messages.
Link where the log4net is available :
https://logging.apache.org/log4net/release/example-apps.html
Codeproject demo to get started :
http://www.codeproject.com/Articles/8245/A-Brief-Introduction-to-the-log-net-logging-librar
Upvotes: 1