Upgrade elmah.io from v3 to v4
There is a new major version update named 4.x
on all client packages. All integrations are based on the Elmah.Io.Client
package which has switched from using AutoRest to NSwag. We have tried supporting most of the existing code from the 3.x
packages, but some minor code changes may be needed after upgrading. This guide will go through the changes needed and potential problems when upgrading.
You may experience problems where NuGet refuses to upgrade an Elmah.Io.*
package. We experienced this when referencing more Elmah.Io.*
packages from the same project. Like if you would reference both Elmah.Io.AspNetCore
and Elmah.Io.Extensions.Logging
from the same project. Upgrading in this scenario can be achieved in one of the following ways:
- Uninstall all
Elmah.Io.*
packages and install them one by one. - Install the
4.x
version of theElmah.Io.Client
NuGet package. Then upgrade the remainingElmah.Io.*
NuGet packages one by one. Finally, uninstall theElmah.Io.Client
package.
Upgrading Elmah.Io.Client
If you are using the Elmah.Io.Client
package directly, you can simply upgrade that package through NuGet:
Update-Package Elmah.Io.Client
This installs the latest 4.x client. Most people are using one of the integrations with ASP.NET Core, Serilog, NLog, or similar. There are new major versions of these packages available as well.
Code changes
As mentioned, some code changes may be required on your part after upgrading. Most of the API stayed the same, but NSwag generates output differently from AutoRest in some cases. Here's a list of changes needed:
- Remove any references to
Elmah.Io.Client.Models
. All generated classes are now in theElmah.Io.Client
namespace. - Replace any reference to
IMessages
,IHeartbeats
, and similar toIMessagesClient
,IHeartbeatsClient
, and similar. - Replace any instances of
new ElmahioAPI(new ApiKeyCredentials(apiKey));
withElmahioAPI.Create(apiKey);
. TheApiKeyCredentials
class was specific to AutoRest and has therefore been removed. - Collection types on messages like
Data
,ServerVariables
, etc. are now of typeICollection
and notIList
. This means you can no longer use indexers on these properties. To use indexer you can callToList()
on each collection. - Properties of type
DateTime
are replaced withDateTimeOffset
. This shouldn't require any changes on your part since you can assign a value of typeDateTime
to a property of typeDateTimeOffset
. - You no longer need to make the following cast:
(ElmahioAPI)ElmahioAPI.Create(apiKey)
. TheIElmahioAPI
interface will have all the properties you need from the client. - If you for some reason manually installed the
Microsoft.Rest.ClientRuntime
package you can remove that after upgradingElmah.Io.Client
to v4. Unless you have other dependencies onMicrosoft.Rest.ClientRuntime
. - The
OnMessageFail
event, available on theIMessagesClient
interface (previously justIMessages
), does now trigger more often. On v3, this event would only trigger on timeouts connecting with the server, when the server returned500
, and similar. In v4, the event will trigger on every failing request, meaning a request where the response contains a status code >=400
. This will make it a lot easier to make smart choices on the client when something fails. An example of this could be to implement a circuit breaker pattern or a local processing queue on the client when the elmah.io API starts returning429
(too many requests).
Upgrading Elmah.Io.AspNetCore
Upgrading the Elmah.Io.AspNetCore
package can be done through NuGet:
Update-Package Elmah.Io.AspNetCore
Code changes
Besides the changes mentioned in the section about the Elmah.Io.Client
package, there's a single change in the Elmah.Io.AspNetCore
v4 package as well:
- The
ElmahIoExtensions
class has been moved from theElmah.Io.AspNetCore
namespace to theMicrosoft.Extensions.DependencyInjection
namespace. TheElmahIoExtensions
class contains theUseElmahIo
andAddElmahIo
methods that you call in yourStartup.cs
file. This change should not cause any compile errors. For simple installations without custom options, you can most likely remove theusing Elmah.Io.AspNetCore;
line from theStartup.cs
file. Visual Studio will tell if that line is no longer needed.
Troubleshooting
Could not load file or assembly 'Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'
Elmah.Io.Client
requires Newtonsoft.Json
version 10.0.3
or newer. Please upgrade to fix this error.
This article was brought to you by the elmah.io team. elmah.io is the best error management system for .NET web applications. We monitor your website, alert you when errors start happening, and help you fix errors fast.
See how we can help you monitor your website for crashes Monitor your website