IdentityServer3 - Exception handling - c#

Is there a way to handle exceptions ourselves. We have custom user service code inside our identityserver project and would like to know without diving through logs when errors occur.
We have a centralized error logger for all our apps. I'd imagine something similar needed if using 3rd party exception lib (airbrake etc).
Is there something possible at the moment or is this ticket solving my problem
https://github.com/IdentityServer/IdentityServer3/issues/2012

If you care about the error logging - the event service will log all unhandled exceptions.
The issue you mentioned would allow you to have more control over direct error handling (e.g. setting a custom http response) - but that's backlog right now.

Related

Why receive weird error messages asp.net mvc "elmah.mvc logging library"?

I have web application developed using Asp.Net MVC 5.
I am integrated Elmah.MVC error logging library for error logging and reporting.
I got weird error messages
like the following:
System.Web.HttpException: The controller for path '/manager/html' was not found or does not implement IController.
The source of request was the following ip 221.194.44.229
which is in China.
Another message:
System.Web.HttpException: The controller for path '/888/pakistani-hackers-forcing-pilots-listen-pakistan-kashmir' was not found or does not implement IController.
The source of request was the following ip 39.45.204.204
which is in Pakistan.
I do not know if elmah.mvc is contains malware or such trojan or myserver was hacked how to investigate that issue and where is problems come from.
Do not know if that the correct place to ask such question or not
Mainly there is some one trying to request apath that is not on your site.
The idia is to make you read the massage in the requested path ( like the secound error from your post) that is som kind of spam.
There is nothing to worry about? This happened every day.
But i think you need to enable custom error pages if you are not already do.

ASP.NET web application in Azure - How to log errors?

I have a web application deployed to azure but I don't know how to log errors.
For testing purposes I have this ForceError method:
public string ForceError()
{
throw new Exception("just a test exception");
return "ok";
}
Which causes and error like this:
On Azure I enabled all Diagnostic logs like this:
But the error I forced does not appear in selected storage container.
Do you know what should I do to start logging all the errors from the application?
I am afraid just throwing an exception doesn't work in Azure Web application logging.
ASP.NET applications can use the System.Diagnostics.Trace class to log information to the application diagnostics log. The four methods in example below correspond with the diagnostic log levels:
Trace.TraceError("Message"); // Write an error message
Trace.TraceWarning("Message"); // Write a warning message
Trace.TraceInformation("Message"); // Write an information message
Trace.WriteLine("Message"); // Write a verbose message
Besides the basic information for logged events, blob storage log additional information such as the instance ID, thread ID, and a more granular timestamp (tick format) in CSV.
A great article here about logging tips and tools.
See also the Reference to the official Azure Web Apps Logging Document.
On Azure Websites, best way to log would be Application Insights, you can use free version to get insights about crashes/speed/performance.
However, Application Insights is little slower if you enable everything. But if you customize it and enable only error logging, it would push all logs to your azure application insights account and you will be able to monitor/analyze it very nicely.
For more details:
https://azure.microsoft.com/en-in/documentation/articles/app-insights-api-custom-events-metrics/
Instead of automatically configuring Application Insights, I would suggest, take an empty project, setup application insights. Notice all added config files and nuget packages. There is some insight config file, except application key/signature, you can turn off everything.
Only when you want to track an exception manually, you can create TelemetryClient and call TrackException method. You can pass more details if you need.

catching request on exception in WCF

I have few webservices in my solution, they use NLOG for logging into the database, I want to catch the Request whenever there is an Exception , currently all the request and response calls are being logged into the database and I want to change it log only the Requests upon exception ..I did some research but did not find any proper answer, if you could give me some example than it could be verymuch helpful
I think you should try Application_Error method in Global.asax. It can catch any unhandled exceptions of application.
Documentation here: http://msdn.microsoft.com/ru-ru/library/24395wz3%28v=vs.100%29.aspx

updating elmah log-entries

I am using ELMAH to log exceptions thrown in my ASP.NET MVC project.
The logging works like a charm, but i want to store additional information on errors. For this purpose the user has a text-area on the friendly error-page so he can enter for example which steps he took before the error occurred...
The plan was to add the additional data to the exception and then update the entry.
Model.Exception.Data.Add("userData", stuff);
My problem is, that ELMAH writes the db-entry BEFORE he redirects to the friendly error-page.
Is there a way to tell elmah to 'update' a log-entry with custom information?
i solved it by deleting the entry and then re-insert it using the server-variables for the user-text.

Returning results/erros from WCF services. Complex type or an exception?

A few days ago I asked a very similar question. I was about returning values/errors inside the application. I accept an answer to not return error as and object but throw an custom exceptions.
Now, I'm not exactly sure how to deal with it using WCF services. I wish the service will be as simple as it could be for client.
Speaking very generally, my project looks like that:
Client -> WCF Service application -> Database.
Inside WCF app I've got my own exception class, and it works fine. But let's say client want sth from db. My question is:
What should I return to the client outside my app?
A. Complex type: A value with meta data (information about a possible error[1]). And when really unexpected error occurs throw an exception.
B. Just a value (when possible error occurs - throw an exception)
[1] - invalid string format, can't connect to database or sth like that. I mean - If I know what the error exactly is - why throw an exception to client - I'm not sure about that.
The decision how to tackle this problem depends on the client. If you have to support Silverlight Clients, throwing exceptions is out of the picture because Silverlight Clients using the browser HTTP Stack cannot deal with them. For Silverlight Clients I generally recommend (and use myself) the approach described here.
By design, WCF hides exceptions from the client. It's up to the developer to determine what, if any, information is returned to the client when an exception occurs.
I would look at using FaultContract or FaultContract<T>, and return exceptions that you wish to via that mechanism.
Here's some articles to look at:
Fault Contract
WCF Tutorial Fault Contract
You might also want to look at IErrorHandler for WCF:
IErrorHandler Interface

Categories