My current project structure is made to do logging of exceptions and such into the database instead of log files.
In order to log down details, it goes through web services of another project (logToDBService).
So I'm wondering that if by chance the web service fails, I will not be able to log down new message.
To counter this, for those failed logs, I thought of logging it down into csv so it can be uploaded into the database manually.
And for this to handled by the system without configuring additional permission, what I can think of at the moment is to introduce a web service (logToCSVService) directly in the same asp.net application, so when the logging at the logToDBService fails, it execute logToCSVService.
I use log4net. It can handle database, files, email etc.
We've used ELMAH for logging errors to a database and also to an email address as a backup. It works quite well and has a lot of developers supporting it. Check out more about ELMAH here:
http://code.google.com/p/elmah/
Related
I want to log exception in my project through global.asax file into database but from my presentation layer I won't be able to access the data layer because my presentation layer communcicates with data layer via webservices, so my question is should i create service to log exception to my database.
this is my architecture
Should I create a service to log exception to my database?
No.
If an error occurs in your web service, log it in your web service. Don't propagate that error to the UI and expect the UI to report that error back to the same or another web service.
It's another story if you want to report errors that occur in your UI. You could opt to report such errors through a service, but what if the error is network-related and the log service is unreachable? Rather log as local to the application as you can.
It depends on what you mean by errors in the presentation tier. Errors in the server side code, e.g. WebForms code behind? Or errors in the user's browser? If the latter, you obviously need some network-based service (there are many third party products for collecting errors in browsers by embedding a bit of JavaScript)
As for your server side components, don't think of logging as a mechanism of your data layer just because it writes to a database. Think of it as a cross cutting concern that just happens to be implemented via a database at the moment. I would simply use a standard logging library such as Log4Net or Serilog for this across the layers, not attempt to wrap it in your own abstractions within the data layer.
You also generally don't want to use exactly the same persistence configuration for logging as for data access in general. For instance logging should often be performed to a separate database for operational reasons such as backup policies. Enlisting your log writes in the same transaction management mechanism as your business data access is also a recipe for accidentally rolling back writes to the log when an error occurred, leaving without any knowledge of the error.
Generally, I would inject TraceListeners and adjust trace level through app.config and Web.config. And I understand that IIS will restart the Web app after the Web.config is updated and the last HTTP request is done and new HTTP requests will be pending before the new instance is created. I have been doing this for years no problem.
However, if I deploy the Web app to Azure managed services, or I have many (clustered) instances of the Web app, I am not sure if updating / uploading Web.config to each instance is still a good practice? Is there some alternative/better method to change the trace level for System.Diagnostics.TraceListeners?
And what if I deploy to AWS or alike for clustered services?
You got it right! updating / uploading Web.config to each instance is not bad but could be tedious task,or error prone approach. Rather,
Would recommend to go with Application Insights,an extensible analytics service that monitors your live web application.
Just install a small instrumentation package in your application, and set up an Application Insights resource in the Microsoft Azure portal.
Performance impact would be minimal as,tracking calls are non-blocking, and are batched ; sent in a separate thread.
Telemetry types such as 'Exception traces from both server and client', 'Diagnostic log traces' and many more helps you understand how your app is performing and how it's being used.
Also you can perform Diagnostic search on instances of requests, exceptions, custom events, log traces, page views, dependency and AJAX calls.
For more information do read : Application Insights - introduction
Thanks,
Kasam Shaikh
I am developing asp.net application using log4net to log the errors, however if I want to change the error log format I must change the application code again after publishing into production,
My question is which is the best option to change(error log for third party API's) the error log without affecting the production server?
Configuring log4net using config files will let you to change logging without touching code
http://www.codeproject.com/Articles/140911/log-net-Tutorial
On a development environment, my web application is properly logging all messages. On the stage environment, the session_end event in global.asax is logged but nothing outside of global.asax gets logged. On dev I can see a basic log when I launch the application showing me logging on, but nothing in stage.
-code is same in both environments
-.NET 4.0 web application deployed to IIS
-log4net.config is same in both environments
-logs to text file on same drive as application that runs it
-logger is instantiated in static class, used through whole application.
-global.asax application_start configures logger by building FileInfo object that points to log4net.config and doing this log4net.Config.XmlConfigurator.ConfigureAndWatch(file);
Does anyone have any advice? I'm sorry if this question is vague or needs more information. I'm unsure where to begin with troubleshooting this. I'll add any requested information.
The user from your application pool needs to have write rights to the logging directory, check is the rights on both environments are the same.
I have a very complicated and big project. There are so many web service calls inside project. All service calls are logged in different tables on database. I need a central log mechanism to avoid all these different log tables.
I think there must be something like Soap Toolkit on client side to catch all service calls. How can I catch the calls and responses to log them to a desired database.?
First of all, it is not a good idea to log to a database. There are several reasons for it, e.g. if, for some reason, there is an exception related to database, it will never get logged.
I would recommend using Log4net from Apache. Here is a good article on how to use log4net in asp.net project. It is a highly efficient and configurable method of logging.