Skip to content

Commit 2377fac

Browse files
committed
Add logging
1 parent f314b87 commit 2377fac

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

DNN Platform/Library/ComponentModel/ComponentFactory.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@ namespace DotNetNuke.ComponentModel
77
using System.Collections;
88
using System.Collections.Generic;
99

10+
using DotNetNuke.Instrumentation;
11+
1012
public static class ComponentFactory
1113
{
14+
private static readonly ILog Logger = LoggerSource.Instance.GetLogger(typeof(ComponentFactory));
15+
1216
public static IContainer Container { get; set; }
1317

1418
public static void InstallComponents(params IComponentInstaller[] installers)
@@ -200,6 +204,7 @@ private static void VerifyContainer()
200204
{
201205
if (Container == null)
202206
{
207+
Logger.Warn("Container was null, instantiating SimpleContainer");
203208
Container = new SimpleContainer();
204209
}
205210
}

DNN Platform/Library/ComponentModel/ContainerWithServiceProviderFallback.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ namespace DotNetNuke.ComponentModel;
66
using System;
77
using System.Collections;
88

9+
using DotNetNuke.Instrumentation;
10+
911
using Microsoft.Extensions.DependencyInjection;
1012

1113
/// <summary>A container which gets components from an <see cref="IServiceProvider"/> for components not registered.</summary>
1214
public class ContainerWithServiceProviderFallback : IContainer
1315
{
16+
private static readonly ILog Logger = LoggerSource.Instance.GetLogger(typeof(ContainerWithServiceProviderFallback));
1417
private readonly IContainer container;
1518
private readonly IServiceProvider serviceProvider;
1619

@@ -115,7 +118,18 @@ public object GetComponent(string name)
115118

116119
/// <inheritdoc />
117120
public TContract GetComponent<TContract>()
118-
=> this.container.GetComponent<TContract>() ?? this.serviceProvider.GetService<TContract>();
121+
{
122+
Logger.Trace($"Getting component for {typeof(TContract).FullName}");
123+
var service = this.container.GetComponent<TContract>();
124+
if (service is not null)
125+
{
126+
Logger.Trace($"Got component for {typeof(TContract).FullName} from container");
127+
return service;
128+
}
129+
130+
Logger.Trace($"Getting component for {typeof(TContract).FullName} from service provider");
131+
return this.serviceProvider.GetService<TContract>();
132+
}
119133

120134
/// <inheritdoc />
121135
public TContract GetComponent<TContract>(string name)

0 commit comments

Comments
 (0)