| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="Log.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | using Microsoft.Extensions.Logging; |
| | | 8 | | using Microsoft.Extensions.Logging.Abstractions; |
| | | 9 | | |
| | | 10 | | namespace MyNet.Utilities.Logging; |
| | | 11 | | |
| | | 12 | | /// <summary> |
| | | 13 | | /// Provides a static logging utility that allows for creating loggers using a configurable logger factory, with a conve |
| | | 14 | | /// </summary> |
| | | 15 | | /// <typeparam name="T">The type to use as the logger category.</typeparam> |
| | | 16 | | public static class Log<T> |
| | | 17 | | { |
| | | 18 | | /// <summary> |
| | | 19 | | /// Gets a logger instance for the specified category type using the configured logger factory. This property provid |
| | | 20 | | /// </summary> |
| | 3 | 21 | | public static ILogger Instance => Log.Factory.CreateLogger<T>(); |
| | | 22 | | } |
| | | 23 | | |
| | | 24 | | /// <summary> |
| | | 25 | | /// Provides a static logging utility that allows for creating loggers using a configurable logger factory. |
| | | 26 | | /// </summary> |
| | | 27 | | public static class Log |
| | | 28 | | { |
| | | 29 | | /// <summary> |
| | | 30 | | /// Gets or sets the logger factory used to create loggers. By default, it is set to a null logger factory that prod |
| | | 31 | | /// </summary> |
| | | 32 | | public static ILoggerFactory Factory { get; set; } = NullLoggerFactory.Instance; |
| | | 33 | | |
| | | 34 | | /// <summary> |
| | | 35 | | /// Creates a logger for the specified category type using the configured logger factory. |
| | | 36 | | /// </summary> |
| | | 37 | | /// <typeparam name="T">The type to use as the logger category.</typeparam> |
| | | 38 | | /// <returns>A logger instance for the specified category type.</returns> |
| | | 39 | | public static ILogger<T> Create<T>() => Factory.CreateLogger<T>(); |
| | | 40 | | |
| | | 41 | | /// <summary> |
| | | 42 | | /// Creates a logger for the specified category name using the configured logger factory. |
| | | 43 | | /// </summary> |
| | | 44 | | /// <param name="category">The category name for the logger.</param> |
| | | 45 | | /// <returns>A logger instance for the specified category name.</returns> |
| | | 46 | | public static ILogger Create(string category) => Factory.CreateLogger(category); |
| | | 47 | | } |
| | | 48 | | |