https://github.com/BlazorExtensions/Logging
Microsoft Extension Logging implementation for Blazor
https://github.com/BlazorExtensions/Logging
blazor logging logging-library microsoft-extensions-logging wasm web-assembly webassembly
Last synced: 27 days ago
JSON representation
Microsoft Extension Logging implementation for Blazor
- Host: GitHub
- URL: https://github.com/BlazorExtensions/Logging
- Owner: BlazorExtensions
- License: mit
- Created: 2018-05-05T03:43:18.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2024-07-09T21:23:54.000Z (10 months ago)
- Last Synced: 2025-03-19T11:16:45.995Z (about 1 month ago)
- Topics: blazor, logging, logging-library, microsoft-extensions-logging, wasm, web-assembly, webassembly
- Language: C#
- Size: 499 KB
- Stars: 216
- Watchers: 11
- Forks: 32
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/BlazorExtensions/Logging/actions)
[](https://www.nuget.org/packages/Blazor.Extensions.Logging)
[](https://www.nuget.org/packages/Blazor.Extensions.Logging)
[](https://github.com/BlazorExtensions/Logging/blob/master/LICENSE)# Blazor Extensions
Blazor Extensions is a set of packages with the goal of adding useful features to [Blazor](https://blazor.net).
# Blazor Extensions Logging
This package is an implementation for the [Microsoft Extensions Logging](https://github.com/aspnet/Logging) abstraction to support
using the ```ILogger``` interface in your Blazor code.When the component is configured, all the log statements will appear in the browser's developer tools console.
# Features
## Content to log
The logger supports the same string formatting that MEL provides, together with named parameter replacement in the message.
Additionaly, you're able to log an object in the browser console. You can expand members and hierachies to see what's contained within.
If you want to log an enumerable list of objects, then the browser side component will display it by calling ```console.table```.
## Filtering
The implementation supports the ```ILoggerFactory```-based filtering configuration that is supplied by the Microsoft Extension Logging abstraction.
To keep it lightweight, [Microsoft Extensions Configuration](https://github.com/aspnet/Configuration) based configuration is not supported; the logger can be only configured in code.
## Log levels
The logger supports the [LogLevels](https://github.com/aspnet/Logging/blob/master/src/Microsoft.Extensions.Logging.Abstractions/LogLevel.cs) defined in MEL.
Some of the log levels are not available as distinct methods in the browser's developer tool, so the browser side component does some [mapping](https://github.com/BlazorExtensions/Logging/blob/master/src/Blazor.Extensions.Logging.JS/src/BrowserConsoleLogger.ts#L13).
# Sample configuration
## Setup
The following snippet shows how to setup the browser console logger by registering it for dependency injection in the ```Program.cs``` of the application.
```c#
// Add Blazor.Extensions.Logging.BrowserConsoleLogger
builder.Services.AddLogging(builder => builder
.AddBrowserConsole()
.SetMinimumLevel(LogLevel.Trace)
);
```## Usage
The following snippet shows how to consume the logger in a Blazor component.
```c#
@inject ILogger logger@functions {
protected override async Task OnInitializedAsync()
{
logger.LogDebug("MyComponent init");
}
}
```If you want to consume it outside of a ```cshtml``` based component, then you can use the ```Inject``` attribute to inject it into the class.
```c#
[Inject]
protected ILogger Logger {get;set;}public void LogSomething()
{
Logger.LogDebug("Inside LogSomething");
}
```# Contributions and feedback
Please feel free to use the component, open issues, fix bugs or provide feedback.
# Contributors
The following people are the maintainers of the Blazor Extensions projects:
- [Attila Hajdrik](https://github.com/attilah)
- [Gutemberg Ribiero](https://github.com/galvesribeiro)