"Secret" elmah.io features #3 - Automate tasks with elmah.io CLI

In this third post in the series of "secret" elmah.io features, I want to introduce you to the elmah.io Command Line Interface (CLI). While you probably spend most of your elmah.io-related time inside the UI, the CLI offers some interesting possibilities not available through the web app.

In this post, I'll show what I believe are the two most usable and helpful features of the elmah.io CLI. There are a lot of sub-commands so feel free to play around with it.

The elmah.io CLI is available as a dotnet tool, meaning that it can easily be installed through NuGet:

dotnet tool install --global Elmah.Io.Cli

Once installed, the CLI can be executed by typing elmahio in the Command Prompt:

Let's jump right into the first use case.

Diagnose an elmah.io installation

While we try to create an installation process as smoothly as possible and combine it with what we hope is excellent documentation, problems getting an application to log to elmah.io occur from time to time. We've had a process for what to ask for when people write our support with installation issues for years. I realized that most of the common problems and/or misconfiguration issues can be automatically checked using code. Say hello to the diagnose command:

As the description says, the diagnose command will look for issues with an elmah.io installation in the current directory or a directory of choice. The command supports most of the client packages and will output any warnings or errors found during code inspection.

Let me demonstrate with an ASP.NET Core project with a common configuration issue. The Elmah.Io.AspNetCore package is correctly installed but only the AddElmahIo method is added to the Program.cs file. If you are familiar with the Elmah.Io.AspNetCore package you will know that a method named UseElmahIo needs to be called as well. When running the diagnose command you will see the following output:

Export log messages

The second subcommand I want to introduce you to is the export command:

We try to crank in as many useful features in the UI as possible, but sometimes you just want to play with data in Excel, Google Sheets, or similar. As you may have already figured, the export command will let you do just that by exporting one or more log messages from a log on elmah.io.

Let us provide the missing options to export log data from the last day:

By specifying an API key with permission to read data, the log ID, and a date range, we get all log messages from that period exported to a file named Export-638466237280731878.json. This can be imported to a tool of your choice. In this case, I'm using Google Sheets with the Simple JSON Import add-on: