Logging from Console

Even though elmah.io support various logging frameworks like Serilog, log4net and NLog, logging from a simple console application is dead simple. Since we currently provide two different versions of our API, the examples are split by version.

To start logging, install the Elmah.Io.Client NuGet package (in either version 2.x or 3.x):

Install-Package Elmah.Io.Client

Version 3.x

Create a new ElmahioAPI:

var logger = ElmahioAPI.Create("API_KEY");

Replace API_KEY with your API key (Where is my API key?).

The elmah.io client supports logging in different log levels much like other logging frameworks for .NET:

var logId = new Guid("LOG_ID");
logger.Messages.Fatal(logId, new ApplicationException("A fatal exception"), "Fatal message");
logger.Messages.Error(logId, new ApplicationException("An exception"), "Error message");
logger.Messages.Warning(logId, "A warning");
logger.Messages.Information(logId, "An info message");
logger.Messages.Debug(logId, "A debug message");
logger.Messages.Verbose(logId, "A verbose message");

Replace LOG_ID with your log ID from elmah.io (Where is my log ID?).

Version 2.x

Create a new Loggerand assign it to a variable of type ILogger:

Elmah.Io.Client.ILogger logger = new Elmah.Io.Client.Logger(new Guid("LOG_ID"));

Replace LOG_ID with your log ID from elmah.io (Where is my log ID?).

The elmah.io client supports logging in different log levels much like other logging frameworks for .NET:

logger.Verbose("Verbose message");
logger.Debug("Debug message");
logger.Information("Information message");
logger.Warning("Warning message");
logger.Error("Error message");
logger.Fatal("Fatal message");

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.

Monitor your website



Comments