diff --git a/Framework/Intersect.Framework.Core/Plugins/Interfaces/CreateLoggerOptions.cs b/Framework/Intersect.Framework.Core/Plugins/Interfaces/CreateLoggerOptions.cs index 5c47051f27..a01d869680 100644 --- a/Framework/Intersect.Framework.Core/Plugins/Interfaces/CreateLoggerOptions.cs +++ b/Framework/Intersect.Framework.Core/Plugins/Interfaces/CreateLoggerOptions.cs @@ -24,7 +24,12 @@ public record struct CreateLoggerOptions public string Name { get; init; } /// - /// The context type of the logger. + /// The context name of the logger. This takes priority over . /// - public Type ContextType { get; init; } + public string? ContextName { get; init; } + + /// + /// The context type of the logger. This will be ignored if is set. + /// + public Type? ContextType { get; init; } } \ No newline at end of file diff --git a/Intersect (Core)/Plugins/Helpers/LoggingHelper.cs b/Intersect (Core)/Plugins/Helpers/LoggingHelper.cs index b377b0aee8..ff7cdca572 100644 --- a/Intersect (Core)/Plugins/Helpers/LoggingHelper.cs +++ b/Intersect (Core)/Plugins/Helpers/LoggingHelper.cs @@ -51,7 +51,7 @@ private static Logger CreateLogger(IManifestHelper manifest, CreateLoggerOptions public ILogger Plugin { get; } - internal LoggingHelper(ILogger applicationLogger, IManifestHelper manifest) + internal LoggingHelper(ILogger applicationLogger, IManifestHelper manifest, PluginReference pluginReference) { mManifest = manifest; @@ -60,15 +60,28 @@ internal LoggingHelper(ILogger applicationLogger, IManifestHelper manifest) new CreateLoggerOptions { Console = Debugger.IsAttached ? LogLevel.Debug : LogLevel.None, File = LogLevel.Information, + ContextName = manifest.Name, + ContextType = pluginReference.EntryType, } ); } /// - public ILogger CreateLogger(CreateLoggerOptions createLoggerOptions) => - new SerilogLoggerFactory(CreateLogger(mManifest, createLoggerOptions)).CreateLogger( - createLoggerOptions.ContextType - ); + public ILogger CreateLogger(CreateLoggerOptions createLoggerOptions) + { + var factory = new SerilogLoggerFactory(CreateLogger(mManifest, createLoggerOptions)); + if (createLoggerOptions.ContextName is { } contextName && !string.IsNullOrWhiteSpace(contextName)) + { + return factory.CreateLogger(contextName); + } + + if (createLoggerOptions.ContextType is { } contextType) + { + return factory.CreateLogger(contextType); + } + + return factory.CreateLogger("Plugin"); + } /// public ILogger CreateLogger(CreateLoggerOptions createLoggerOptions) => diff --git a/Intersect (Core)/Plugins/Plugin.cs b/Intersect (Core)/Plugins/Plugin.cs index caa312f2d4..e8c6f5d45d 100644 --- a/Intersect (Core)/Plugins/Plugin.cs +++ b/Intersect (Core)/Plugins/Plugin.cs @@ -20,7 +20,7 @@ internal static Plugin Create( IApplicationContext applicationContext, IManifestHelper manifest, PluginReference reference - ) => new Plugin(manifest, new LoggingHelper(applicationContext.Logger, manifest), reference); + ) => new Plugin(manifest, new LoggingHelper(applicationContext.Logger, manifest, reference), reference); // ReSharper disable once NotNullMemberIsNotInitialized // Plugin instance is created at the Discovery phase and Configuration is loaded afterwards