Forwards JavaScript console logs to ASP.NET Core applications.
| Windows | Linux | NuGet |
|---|---|---|
JavaScript Logging is a small library which forwards client-side JavaScript logging via console.info, console.error, etc. to your ASP.NET Core application and logs the message with the equivalent log level using the ILogger interface. This library is inspired by the blogpost and sample application of Hisham and I took the liberty to create a NuGet package from his idea.
Install the package from NuGet:
dotnet add package Webenable.Logging.JavaScript
Configure the logging library in your Startup class:
public void ConfigureServices(IServiceCollection services)
{
services.AddJavaScriptLogging();
// ...
}The library will automatically inject the necessary JavaScript and register a middleware to handle the logging HTTP requests.
The library uses jQuery to post log messages to your application using AJAX. Please make sure that jQuery is available when using this library.
Any calls to the following console methods are intercepted and will post a log message to the server which logs the message with the corresponding log level. The default behavior of the console method is executed as well.
console.traceconsole.debugconsole.infoconsole.warnconsole.error
Please note that the console.log method is not intercepted.