|
1 | | -[](https://dotnet-ci.visualstudio.com/DotnetCI/_build/latest?definitionId=10&branch=master) |
2 | | -[](https://www.nuget.org/packages/Blazor.Extensions.Logging) |
3 | | -[](https://www.nuget.org/packages/Blazor.Extensions.Logging) |
4 | | -[](https://github.com/BlazorExtensions/Logging/blob/master/LICENSE) |
5 | | - |
6 | | -# Blazor Extensions |
7 | | - |
8 | | -Blazor Extensions is a set of packages with the goal of adding useful features to [Blazor](https://blazor.net). |
9 | | - |
10 | | -# Blazor Extensions Logging |
11 | | - |
12 | | -This package is an implementation for the [Microsoft Extensions Logging](https://github.com/aspnet/Logging) abstraction to support |
13 | | -using the ```ILogger``` interface in your Blazor code. |
14 | | - |
15 | | -When the component is configured, all the log statements will appear in the browser's developer tools console. |
16 | | - |
17 | | -# Features |
18 | | - |
19 | | -## Content to log |
20 | | - |
21 | | -The logger supports the same string formatting that MEL provides, together with named parameter replacement in the message. |
22 | | - |
23 | | -Additionaly, you're able to log an object in the browser console. You can expand members and hierachies to see what's contained within. |
24 | | - |
25 | | -If you want to log an enumerable list of objects, then the browser side component will display it by calling ```console.table```. |
26 | | - |
27 | | -## Filtering |
28 | | - |
29 | | -The implementation supports the ```ILoggerFactory```-based filtering configuration that is supplied by the Microsoft Extension Logging abstraction. |
30 | | - |
31 | | -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. |
32 | | - |
33 | | -## Log levels |
34 | | - |
35 | | -The logger supports the [LogLevels](https://github.com/aspnet/Logging/blob/master/src/Microsoft.Extensions.Logging.Abstractions/LogLevel.cs) defined in MEL. |
36 | | - |
37 | | -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/Initialize.ts#L35). |
38 | | - |
39 | | -# Sample configuration |
40 | | - |
41 | | -## Setup |
42 | | - |
43 | | -The following snippet shows how to setup the browser console logger by registering it for dependency injection in the ```Startup.cs``` of the application. |
44 | | - |
45 | | -```c# |
46 | | -public void ConfigureServices(IServiceCollection services) |
47 | | -{ |
48 | | - services.AddLogging(builder => builder |
49 | | - .AddBrowserConsole() // Add Blazor.Extensions.Logging.BrowserConsoleLogger |
50 | | - .SetMinimumLevel(LogLevel.Trace) |
51 | | - ); |
52 | | -} |
53 | | -``` |
54 | | - |
55 | | -## Usage |
56 | | - |
57 | | -The following snippet shows how to consume the logger in a Blazor component. |
58 | | - |
59 | | -```c# |
60 | | -@inject ILogger<Index> logger |
61 | | - |
62 | | -@functions { |
63 | | - protected override async Task OnInitAsync() |
64 | | - { |
65 | | - logger.LogDebug("MyComponent init"); |
66 | | - } |
67 | | -} |
68 | | -``` |
69 | | - |
70 | | -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. |
71 | | - |
72 | | -```c# |
73 | | -[Inject] |
74 | | -protected ILogger<MyClass> Logger {get;set;} |
75 | | - |
76 | | -public void LogSomething() |
77 | | -{ |
78 | | - Logger.LogDebug("Inside LogSomething"); |
79 | | -} |
80 | | -``` |
81 | | - |
82 | | -# Contributions and feedback |
83 | | - |
84 | | -Please feel free to use the component, open issues, fix bugs or provide feedback. |
85 | | - |
86 | | -# Contributors |
87 | | - |
88 | | -The following people are the maintainers of the Blazor Extensions projects: |
89 | | - |
90 | | -- [Attila Hajdrik](https://github.com/attilah) |
91 | | -- [Gutemberg Ribiero](https://github.com/galvesribeiro) |
| 1 | +[](https://dotnet-ci.visualstudio.com/DotnetCI/_build/latest?definitionId=10&branch=master) |
| 2 | +[](https://www.nuget.org/packages/Blazor.Extensions.Logging) |
| 3 | +[](https://www.nuget.org/packages/Blazor.Extensions.Logging) |
| 4 | +[](https://github.com/BlazorExtensions/Logging/blob/master/LICENSE) |
| 5 | + |
| 6 | +# Blazor Extensions |
| 7 | + |
| 8 | +Blazor Extensions is a set of packages with the goal of adding useful features to [Blazor](https://blazor.net). |
| 9 | + |
| 10 | +# Blazor Extensions Logging |
| 11 | + |
| 12 | +This package is an implementation for the [Microsoft Extensions Logging](https://github.com/aspnet/Logging) abstraction to support |
| 13 | +using the ```ILogger``` interface in your Blazor code. |
| 14 | + |
| 15 | +When the component is configured, all the log statements will appear in the browser's developer tools console. |
| 16 | + |
| 17 | +# Features |
| 18 | + |
| 19 | +## Content to log |
| 20 | + |
| 21 | +The logger supports the same string formatting that MEL provides, together with named parameter replacement in the message. |
| 22 | + |
| 23 | +Additionaly, you're able to log an object in the browser console. You can expand members and hierachies to see what's contained within. |
| 24 | + |
| 25 | +If you want to log an enumerable list of objects, then the browser side component will display it by calling ```console.table```. |
| 26 | + |
| 27 | +## Filtering |
| 28 | + |
| 29 | +The implementation supports the ```ILoggerFactory```-based filtering configuration that is supplied by the Microsoft Extension Logging abstraction. |
| 30 | + |
| 31 | +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. |
| 32 | + |
| 33 | +## Log levels |
| 34 | + |
| 35 | +The logger supports the [LogLevels](https://github.com/aspnet/Logging/blob/master/src/Microsoft.Extensions.Logging.Abstractions/LogLevel.cs) defined in MEL. |
| 36 | + |
| 37 | +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/Initialize.ts#L35). |
| 38 | + |
| 39 | +# Sample configuration |
| 40 | + |
| 41 | +## Setup |
| 42 | + |
| 43 | +The following snippet shows how to setup the browser console logger by registering it for dependency injection in the ```Startup.cs``` of the application. |
| 44 | + |
| 45 | +```c# |
| 46 | +public void ConfigureServices(IServiceCollection services) |
| 47 | +{ |
| 48 | + services.AddLogging(builder => builder |
| 49 | + .AddBrowserConsole() // Add Blazor.Extensions.Logging.BrowserConsoleLogger |
| 50 | + .SetMinimumLevel(LogLevel.Trace) |
| 51 | + ); |
| 52 | +} |
| 53 | +``` |
| 54 | + |
| 55 | +## Usage |
| 56 | + |
| 57 | +The following snippet shows how to consume the logger in a Blazor component. |
| 58 | + |
| 59 | +```c# |
| 60 | +@inject ILogger<Index> logger |
| 61 | + |
| 62 | +@functions { |
| 63 | + protected override async Task OnInitializedAsync() |
| 64 | + { |
| 65 | + logger.LogDebug("MyComponent init"); |
| 66 | + } |
| 67 | +} |
| 68 | +``` |
| 69 | + |
| 70 | +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. |
| 71 | + |
| 72 | +```c# |
| 73 | +[Inject] |
| 74 | +protected ILogger<MyClass> Logger {get;set;} |
| 75 | + |
| 76 | +public void LogSomething() |
| 77 | +{ |
| 78 | + Logger.LogDebug("Inside LogSomething"); |
| 79 | +} |
| 80 | +``` |
| 81 | + |
| 82 | +# Contributions and feedback |
| 83 | + |
| 84 | +Please feel free to use the component, open issues, fix bugs or provide feedback. |
| 85 | + |
| 86 | +# Contributors |
| 87 | + |
| 88 | +The following people are the maintainers of the Blazor Extensions projects: |
| 89 | + |
| 90 | +- [Attila Hajdrik](https://github.com/attilah) |
| 91 | +- [Gutemberg Ribiero](https://github.com/galvesribeiro) |
0 commit comments