Skip to content

Commit 03f349b

Browse files
committed
Wip
1 parent a177888 commit 03f349b

File tree

7 files changed

+81
-78
lines changed

7 files changed

+81
-78
lines changed

ArtNetSharp/ArtNet.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace ArtNetSharp
1919
public class ArtNet : IDisposable
2020
{
2121
private static readonly Random _random = new Random();
22-
private static ILogger<ArtNet> Logger = ApplicationLogging.CreateLogger<ArtNet>();
22+
private static ILogger<ArtNet> Logger = Logging.CreateLogger<ArtNet>();
2323
private static ArtNet instance;
2424
public static ArtNet Instance
2525
{
@@ -74,7 +74,7 @@ private async void LoopNetwork_DataReceived(object sender, EventArgs e)
7474

7575
public class NetworkClientBag : IDisposable
7676
{
77-
private static readonly ILogger<NetworkClientBag> Logger = ApplicationLogging.CreateLogger<NetworkClientBag>();
77+
private static readonly ILogger<NetworkClientBag> Logger = Logging.CreateLogger<NetworkClientBag>();
7878
private readonly IPEndPoint broadcastEndpoint;
7979
public readonly IPAddress BroadcastIpAddress;
8080
public readonly UnicastIPAddressInformation UnicastIPAddressInfo;
@@ -387,7 +387,7 @@ public static void AddLoggProvider(ILoggerProvider loggerProvider)
387387
{
388388
if (loggerProviders.Contains(loggerProvider))
389389
return;
390-
ApplicationLogging.LoggerFactory.AddProvider(loggerProvider);
390+
Logging.LoggerFactory.AddProvider(loggerProvider);
391391
loggerProviders.Add(loggerProvider);
392392
}
393393

ArtNetSharp/Communication/AbstractInstance.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ protected AbstractInstance(ArtNet _artnet)
295295
{
296296
_random = new Random();
297297
ArtNetInstance = _artnet;
298-
Logger = ApplicationLogging.CreateLogger(this.GetType());
298+
Logger = Logging.CreateLogger(this.GetType());
299299

300300
ArtNetInstance.OnInstanceAdded += ArtNet_OnInstanceAdded;
301301
ArtNetInstance.OnInstanceRemoved += ArtNet_OnInstanceRemoved;

ArtNetSharp/Communication/PortConfig.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace ArtNetSharp.Communication
1212
{
1313
public class PortConfig
1414
{
15-
private static readonly ILogger Logger = ApplicationLogging.CreateLogger<PortConfig>();
15+
private static readonly ILogger Logger = Logging.CreateLogger<PortConfig>();
1616
public virtual PortAddress PortAddress { get; set; }
1717
public Net Net { get => PortAddress.Net; }
1818
public Subnet Subnet { get => PortAddress.Subnet; }

ArtNetSharp/Communication/RemoteClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace ArtNetSharp.Communication
1313
{
1414
public sealed class RemoteClient : INotifyPropertyChanged
1515
{
16-
private static readonly ILogger Logger = ApplicationLogging.CreateLogger<RemoteClient>();
16+
private static readonly ILogger Logger = Logging.CreateLogger<RemoteClient>();
1717
public readonly string ID;
1818
public readonly MACAddress MacAddress;
1919
private IPv4Address ipAddress;

ArtNetSharp/Communication/RemoteClientPort.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace ArtNetSharp.Communication
1212
{
1313
public sealed class RemoteClientPort : INotifyPropertyChanged
1414
{
15-
private static readonly ILogger Logger = ApplicationLogging.CreateLogger<RemoteClientPort>();
15+
private static readonly ILogger Logger = Logging.CreateLogger<RemoteClientPort>();
1616
public readonly IPv4Address IpAddress;
1717
public readonly string ID;
1818
public readonly byte BindIndex;
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,74 @@
1-
using Microsoft.Extensions.Logging;
2-
using System;
3-
using System.Linq;
4-
using System.Runtime.CompilerServices;
5-
using static ArtNetSharp.ApplicationLogging;
6-
7-
[assembly: InternalsVisibleTo("ArtNetTests")]
8-
namespace ArtNetSharp
9-
{
10-
/// <summary>
11-
/// Shared logger
12-
/// </summary>
13-
internal static class ApplicationLogging
14-
{
15-
private static ILoggerFactory loggerFactory;
16-
internal static ILoggerFactory LoggerFactory
17-
{
18-
get
19-
{
20-
if (loggerFactory == null)
21-
{
22-
bool isTest = AppDomain.CurrentDomain.GetAssemblies()
23-
.Any(a => a.FullName.StartsWith("NUnit", StringComparison.OrdinalIgnoreCase));
24-
loggerFactory = Microsoft.Extensions.Logging.LoggerFactory.Create((builder) =>
25-
{
26-
FileProvider fp = isTest ? new FileProvider() : null;
27-
#if Debug
28-
fp ?= new FileProvider();
29-
#endif
30-
if (isTest)
31-
{
32-
builder.AddConsole();
33-
builder.SetMinimumLevel(LogLevel.Trace);
34-
}
35-
if (fp != null)
36-
builder.AddProvider(fp);
37-
});
38-
}
39-
return loggerFactory;
40-
}
41-
}
42-
43-
internal static ILogger<T> CreateLogger<T>() => LoggerFactory.CreateLogger<T>();
44-
internal static ILogger CreateLogger(Type type) => LoggerFactory.CreateLogger(type);
45-
internal static ILogger CreateLogger(string categoryName) => LoggerFactory.CreateLogger(categoryName);
46-
internal static void LogTrace(this ILogger logger, Exception exception)
47-
{
48-
logger.LogTrace(exception, string.Empty);
49-
}
50-
internal static void LogDebug(this ILogger logger, Exception exception)
51-
{
52-
logger.LogDebug(exception, string.Empty);
53-
}
54-
internal static void LogInformation(this ILogger logger, Exception exception)
55-
{
56-
logger.LogInformation(exception, string.Empty);
57-
}
58-
internal static void LogWarning(this ILogger logger, Exception exception)
59-
{
60-
logger.LogWarning(exception, string.Empty);
61-
}
62-
internal static void LogError(this ILogger logger, Exception exception)
63-
{
64-
logger.LogError(exception, string.Empty);
65-
}
66-
internal static void LogCritical(this ILogger logger, Exception exception)
67-
{
68-
logger.LogCritical(exception, string.Empty);
69-
}
70-
}
1+
using Microsoft.Extensions.Logging;
2+
using System;
3+
using System.Linq;
4+
using System.Runtime.CompilerServices;
5+
using static ArtNetSharp.Logging;
6+
7+
[assembly: InternalsVisibleTo("ArtNetTests")]
8+
namespace ArtNetSharp
9+
{
10+
public static class Logging
11+
{
12+
private static ILoggerFactory loggerFactory;
13+
public static ILoggerFactory LoggerFactory
14+
{
15+
get
16+
{
17+
if (loggerFactory == null)
18+
{
19+
bool isTest = AppDomain.CurrentDomain.GetAssemblies()
20+
.Any(a => a.FullName.StartsWith("NUnit", StringComparison.OrdinalIgnoreCase));
21+
loggerFactory = Microsoft.Extensions.Logging.LoggerFactory.Create((builder) =>
22+
{
23+
FileProvider fp = isTest ? new FileProvider() : null;
24+
#if Debug
25+
fp ?= new FileProvider();
26+
#endif
27+
if (isTest)
28+
{
29+
builder.AddConsole();
30+
builder.SetMinimumLevel(LogLevel.Trace);
31+
}
32+
if (fp != null)
33+
builder.AddProvider(fp);
34+
});
35+
}
36+
return loggerFactory;
37+
}
38+
set
39+
{
40+
if(loggerFactory!=null)
41+
throw new InvalidOperationException("LoggerFactory is already set. It can only be set once.");
42+
loggerFactory = value;
43+
}
44+
}
45+
46+
internal static ILogger<T> CreateLogger<T>() => LoggerFactory.CreateLogger<T>();
47+
internal static ILogger CreateLogger(Type type) => LoggerFactory.CreateLogger(type);
48+
internal static ILogger CreateLogger(string categoryName) => LoggerFactory.CreateLogger(categoryName);
49+
internal static void LogTrace(this ILogger logger, Exception exception)
50+
{
51+
logger.LogTrace(exception, string.Empty);
52+
}
53+
internal static void LogDebug(this ILogger logger, Exception exception)
54+
{
55+
logger.LogDebug(exception, string.Empty);
56+
}
57+
internal static void LogInformation(this ILogger logger, Exception exception)
58+
{
59+
logger.LogInformation(exception, string.Empty);
60+
}
61+
internal static void LogWarning(this ILogger logger, Exception exception)
62+
{
63+
logger.LogWarning(exception, string.Empty);
64+
}
65+
internal static void LogError(this ILogger logger, Exception exception)
66+
{
67+
logger.LogError(exception, string.Empty);
68+
}
69+
internal static void LogCritical(this ILogger logger, Exception exception)
70+
{
71+
logger.LogCritical(exception, string.Empty);
72+
}
73+
}
7174
}

ArtNetSharp/Misc/Tools.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace ArtNetSharp
1010
{
1111
public static class Tools
1212
{
13-
private static readonly ILogger Logger = ApplicationLogging.CreateLogger("Tools");
13+
private static readonly ILogger Logger = Logging.CreateLogger("Tools");
1414
public static bool IsAndroid()
1515
{
1616
return

0 commit comments

Comments
 (0)