updating elmah log-entries - c#

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.

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.

IdentityServer3 - Exception handling

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.

Simple Membership and Role Provider in MVC3/MVC4

I'm writting Simple Membership and Role Provider.
I'm trying run the code from post http://www.brianlegg.com/post/2011/05/09/Implementing-your-own-RoleProvider-and-MembershipProvider-in-MVC-3.aspx but on run IIS show me error:
Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Line 39: <providers>
Line 40: <clear />
Line 41: <add name="LocalBankMembershipProvider" type="LocalBank.Helpers.LocalBankMembershipProvider, LocalBank" connectionStringName="LocalBankEntities" />
Line 42: </providers>
Line 43: </membership>
Message Parser Error: Target call threw an exception.
Line: 41
Where I made a mistake at the start of the project?
Convert project using Nuget package from mvc3 to mvc4
how can I fix this error?
Did you followed advise given in comments section on the same link?
Few things to try:
It might be the connection string that is wrong and due to which you are seeing this error. Change the connection string (e.g. data source). If you still see an issue, debug the project and see where exactly it is stuck and what more information you can get. I was able to reproduce this issue and with changes in connection string it was solved.
When you debug you will see it will throw exception when it checks role exists. As per the blog, you need to add default role "Manager":
The only thing to note is there are no roles created. If you look inside the AccountController Register HttpPost action you'll notice that any user who registers through this site is given a default role of "Member". This can be changed, but whatever role this is must first already be created in the Role table. You can do this by writing a script (most likely preferred method) or you can write some hacky code and call it real quick since it will only need to be ran 1 time when first creating roles. Here's some example code you can use to create the "Member" role, modify it to suit your needs.
LocalBankRepository repo = new LocalBankRepository();
repo.AddRole("Member");
repo.Save();
Call those 3 lines from somewhere in your code (or a separate
"initializer" project) and from then on the code should work as
expected. Sorry for the confusion.
If you still face issue share with more details. Hope this helps.

How to display Customised error message on website if its Database goes down

I have a ASP.NET website with SQL SERVER Database. Each time database goes down it shows a .NET error message. Is there any way to display a customised message. For eg: "Sorry, website is currently unavailable."
You would have to use try catch and handle SQL Exception and in the catch block add the customised message to your label.
Get the exception in the Global.asax and redirect them, see this.
Create and set errorpage for your website
Check Web Application Error Hanling

Categories