| | | 1 | | using System; |
| | | 2 | | using System.Globalization; |
| | | 3 | | using Microsoft.Extensions.Logging; |
| | | 4 | | |
| | | 5 | | namespace Jellyfin.Server.ServerSetupApp; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// Startup logger for usage with DI that utilises an underlying logger from the DI. |
| | | 9 | | /// </summary> |
| | | 10 | | /// <typeparam name="TCategory">The category of the underlying logger.</typeparam> |
| | | 11 | | #pragma warning disable SA1649 // File name should match first type name |
| | | 12 | | public class StartupLogger<TCategory> : StartupLogger, IStartupLogger<TCategory> |
| | | 13 | | #pragma warning restore SA1649 // File name should match first type name |
| | | 14 | | { |
| | | 15 | | /// <summary> |
| | | 16 | | /// Initializes a new instance of the <see cref="StartupLogger{TCategory}"/> class. |
| | | 17 | | /// </summary> |
| | | 18 | | /// <param name="logger">The injected base logger.</param> |
| | 21 | 19 | | public StartupLogger(ILogger<TCategory> logger) : base(logger) |
| | | 20 | | { |
| | 21 | 21 | | } |
| | | 22 | | |
| | | 23 | | /// <summary> |
| | | 24 | | /// Initializes a new instance of the <see cref="StartupLogger{TCategory}"/> class. |
| | | 25 | | /// </summary> |
| | | 26 | | /// <param name="logger">The underlying base logger.</param> |
| | | 27 | | /// <param name="groupEntry">The group for this logger.</param> |
| | 21 | 28 | | internal StartupLogger(ILogger logger, StartupLogTopic? groupEntry) : base(logger, groupEntry) |
| | | 29 | | { |
| | 21 | 30 | | } |
| | | 31 | | |
| | | 32 | | IStartupLogger<TCategory> IStartupLogger<TCategory>.BeginGroup(FormattableString logEntry) |
| | | 33 | | { |
| | 0 | 34 | | var startupEntry = new StartupLogTopic() |
| | 0 | 35 | | { |
| | 0 | 36 | | Content = logEntry.ToString(CultureInfo.InvariantCulture), |
| | 0 | 37 | | DateOfCreation = DateTimeOffset.Now |
| | 0 | 38 | | }; |
| | | 39 | | |
| | 0 | 40 | | if (Topic is null) |
| | | 41 | | { |
| | 0 | 42 | | SetupServer.LogQueue?.Enqueue(startupEntry); |
| | | 43 | | } |
| | | 44 | | else |
| | | 45 | | { |
| | 0 | 46 | | Topic.Children.Add(startupEntry); |
| | | 47 | | } |
| | | 48 | | |
| | 0 | 49 | | return new StartupLogger<TCategory>(BaseLogger, startupEntry); |
| | | 50 | | } |
| | | 51 | | |
| | | 52 | | IStartupLogger<TCategory> IStartupLogger<TCategory>.With(ILogger logger) |
| | | 53 | | { |
| | 0 | 54 | | return new StartupLogger<TCategory>(logger, Topic); |
| | | 55 | | } |
| | | 56 | | } |