On Premise to Cloud Migration (Azure) – 15 Best Practices
CTOs often worry about moving to the cloud, and when they do, they overlook the risks involved, which causes them to wonder, 'Why does cloud migration fail?' Facts reveal that 75%...
Kapil Panchal - October 20, 2020
Listening is fun too.
Straighten your back and cherish with coffee - PLAY !
ELMAH Stands for Error Logging Modules and Handlers that offers functionality to logging runtime ASP.NET errors. ELMAH can be utilizing to adjoin error logging abilities in your application without having to re-compile or re-deploy, it creates the process of capturing application errors seamlessly.
When added to a running web application on a machine, exceptions that are thrown trigger event handlers in the ELMAH tool. These event handlers can include logging to various database back-ends, logging which can be viewed from a web portal, and the sending of notification emails, tweets and RSS articles to advise administrators of the problem. ELMAH provides a pluggable implementation of error logging.
An alternative to the health monitoring system is Error Logging Modules and Handlers (ELMAH), a free, open-source error logging system created by Atif Aziz. The most notable difference between the two systems is ELAMH's ability to display a list of errors and the details of a specific error from a web page and as an RSS feed. ELMAH is easier to configure than health monitoring because it only logs errors.
Hereby, we will look at how to execute error management in ASP.Net Core using the ELMAH error management framework and Elmah.io, a cloud-based error management system that toils with ELMAH.
This article depicts how to integrate a simple logger very similar to ELMAH that stores latest errors in memory.
There are three HTTP Modules.
You can add logs, exceptions to elmah.io directly from an ASP.NET Core application using the Elmah.Io.ASPNetCore packages. These packages can be added to the project using the nuget package manager.
Now Call AddElmahIo in the ConfigureServices-method in the Startup.cs file
Replace API_KEY with your API key and LOG_ID. with the log Id of the log you want to log to.
Call UseElmahIo in the Configure-method in the Startup.cs file:
public void ConfigureServices(IServiceCollection services) { services.AddElmahIo(o => { o.ApiKey = "API_KEY"; o.LogId = new Guid("LOG_ID"); }); } public void Configure (IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory fac) { app.UseElmahIo(); }
Now if you have different environments, you should consider adding the API key and log ID in your appsettings.json file
{ "ElmahIo": { "ApiKey": "API_KEY", "LogId": "LOG_ID" }
Now Configuring elmah.io is done by calling the Configure method and instead of AddElmahIo. And Finally, call the UseElmahIo method.
public void ConfigureServices(IServiceCollection services) { services.Configure(Configuration.GetSection("ElmahIo")); services.AddElmahIo(); } public void Configure(IApplicationBuilder app, IHostingEnvironment env) { app.UseElmahIo(); }
You can still configure additional options on the ElmahIoOptions object
public void ConfigureServices(IServiceCollection services) { services.Configure(Configuration.GetSection("ElmahIo")); services.Configure (o => { o.OnMessage = msg => { msg.Version = "2.1.0"; }; }); services.AddElmahIo(); }
elmah.io for ASP.NET Core supports a range of events for hooking into the process of logging messages. Events are registered as actions when installing the elmah.io middleware:
services.AddElmahIo(o => { o.ApiKey = "API_KEY"; o.LogId = new Guid("LOG_ID"); o.OnMessage = message => { message.Version = "40"; }; o.OnError = (message, exception) => { logger.Lo?gError(1, exception, "Error during log to elmah.io"); }; });
The actions provide a mechanism for hooking into the log process. The action registered in the OnMessage property is called by elmah.io just before logging a new message to the API.
Use this action to decorate/enrich your log messages with additional data, like a version number. The OnError action is called if communication with the elmah.io API failed.
Now While elmah.io supports ignore rules serverside, you may want to filter out errors without even hitting the elmah.io API. Using the OnFilter function on the options object, filtering is easy:
services.AddElmahIo(o => { o.OnFilter = message => { return message.Type == "System.NullReferenceException"; }; });
The OnMessage event can be used to filter sensitive form data as well. In the following example, we can remove the server variable named Secret-Key from all messages, before sending them to elmah.io
services.AddElmahIo(options => { options.ApiKey = "API_KEY"; options.LogId = new Guid("LOG_ID"); options.OnMessage = msg => { var item = msg.ServerVariables.FirstOrDefault(x => x.Key == "Secret-Key"); if (item != null) { msg.ServerVariables.Remove(item); } }; });
NLog using the Elmah.Io.NLog target can also be used in ASP.NET Core to send messages to elmah.io. This can be added using the nuget package manager.
NLog for ASP.NET Core applications can be configured in the Startup class. You need to set the target properties with the elmah.io API-KEY and also the LogId. You could also do this in the nlog.config file
Elmah is a perfect way to log the unhandled exceptions in your application. It assists you log errors in SQL Server, Oracle, SQLite, MySQL, PostgreSQL, and even XML files. If you adjoin Elmah.io to the mix, you can review the error logs in a web page remotely and even acquire notifications on the errors if require.
CTOs often worry about moving to the cloud, and when they do, they overlook the risks involved, which causes them to wonder, 'Why does cloud migration fail?' Facts reveal that 75%...
Did you know that 70% of CTOs (Chief Technology Officers) hesitate to adopt Microsoft Power BI because of its myths and misconceptions that float around. What they fail to see is...
Every CTO knows the struggle of managing complex reports. The inefficiency of scattered data, the constant juggling between reporting tools, the challenge of ensuring accurate KPIs...