Skip to content

Commit 38f9cac

Browse files
authored
Replace NETCOREAPP3_1_OR_GREATER with new NET (#828)
1 parent dfff5da commit 38f9cac

2 files changed

Lines changed: 13 additions & 12 deletions

File tree

src/NLog.Extensions.Logging/Logging/NLogBeginScopeParser.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public IDisposable ParseBeginScope<T>(T state)
3939
scopePropertyList = ParseScopeProperties(scopePropertyList);
4040
return ScopeContext.PushNestedStateProperties(scopeObject, scopePropertyList);
4141
}
42-
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER || NET471_OR_GREATER
42+
#if NETSTANDARD2_1_OR_GREATER || NET || NET471_OR_GREATER
4343
else if (state is System.Runtime.CompilerServices.ITuple && ((System.Runtime.CompilerServices.ITuple)state).Length == 2 && ((System.Runtime.CompilerServices.ITuple)state)[0] is string propertyName)
4444
{
4545
return ScopeContext.PushProperty(propertyName, ((System.Runtime.CompilerServices.ITuple)state)[1]);
@@ -239,7 +239,7 @@ public static IDisposable CaptureScopeProperty<TState>(TState scopeProperty, Ext
239239
private static bool TryLookupExtractor<TState>(ExtractorDictionary stateExtractor, TState propertyValue,
240240
out Func<object, KeyValuePair<string, object?>>? keyValueExtractor)
241241
{
242-
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER || NET471_OR_GREATER
242+
#if NETSTANDARD2_1_OR_GREATER || NET || NET471_OR_GREATER
243243
if (propertyValue is System.Runtime.CompilerServices.ITuple && ((System.Runtime.CompilerServices.ITuple)propertyValue).Length == 2 && ((System.Runtime.CompilerServices.ITuple)propertyValue)[0] is string)
244244
{
245245
keyValueExtractor = static (obj) => new KeyValuePair<string, object?>(
@@ -283,7 +283,7 @@ private static bool TryBuildExtractor(Type propertyType, out Func<object, KeyVal
283283
return keyValueExtractor != null;
284284
}
285285

286-
#if !NETSTANDARD2_1_OR_GREATER && !NETCOREAPP3_1_OR_GREATER && !NET471_OR_GREATER
286+
#if !NETSTANDARD2_1_OR_GREATER && !NET && !NET471_OR_GREATER
287287
if (propertyType.GetGenericTypeDefinition() == typeof(ValueTuple<,>))
288288
{
289289
var itemType = propertyType.GetTypeInfo();
@@ -306,13 +306,15 @@ private static bool TryBuildExtractor(Type propertyType, out Func<object, KeyVal
306306
return false;
307307
}
308308

309-
#if !NETSTANDARD && !NETFRAMEWORK
309+
#if NETSTANDARD2_1_OR_GREATER || NET
310310
private static KeyValuePair<string, object?> TypedKeyValueExtractor<TKey, TValue>(object value)
311311
{
312312
var keyValuePair = (KeyValuePair<TKey, TValue>)value;
313313
return new KeyValuePair<string, object?>(keyValuePair.Key?.ToString() ?? string.Empty, keyValuePair.Value);
314314
}
315+
#endif
315316

317+
#if NET
316318
[System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming - Allow reflection of BeginScope args", "IL2070")]
317319
#endif
318320
private static Func<object, KeyValuePair<string, object?>>? BuildKeyValueExtractor(Type propertyType, TypeInfo itemType)
@@ -331,10 +333,7 @@ private static bool TryBuildExtractor(Type propertyType, out Func<object, KeyVal
331333

332334
private static Func<object, KeyValuePair<string, object?>>? BuildKeyValueExtractor(Type propertyType)
333335
{
334-
#if NETSTANDARD || NETFRAMEWORK
335-
var itemType = propertyType.GetTypeInfo();
336-
return BuildKeyValueExtractor(propertyType, itemType);
337-
#else
336+
#if NETSTANDARD2_1_OR_GREATER || NET
338337
if (propertyType.GenericTypeArguments[0] == typeof(string))
339338
{
340339
if (propertyType.GenericTypeArguments[1] == typeof(object))
@@ -363,8 +362,10 @@ private static bool TryBuildExtractor(Type propertyType, out Func<object, KeyVal
363362
var itemType = propertyType.GetTypeInfo();
364363
return BuildKeyValueExtractor(propertyType, itemType);
365364
}
366-
367365
return null;
366+
#else
367+
var itemType = propertyType.GetTypeInfo();
368+
return BuildKeyValueExtractor(propertyType, itemType);
368369
#endif
369370
}
370371

src/NLog.Extensions.Logging/Logging/NLogLogger.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public void Log<TState>(Microsoft.Extensions.Logging.LogLevel logLevel, EventId
5050
_logger.Log(typeof(Microsoft.Extensions.Logging.ILogger), eventInfo);
5151
}
5252

53-
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
53+
#if NETSTANDARD2_1_OR_GREATER || NET
5454
LogEventInfo? GetMessageParametersWithoutBoxing<TState>(LogLevel nLogLogLevel, in EventId eventId, in TState state, Exception? exception, Func<TState, Exception?, string> formatter)
5555
{
5656
if (state is IReadOnlyList<KeyValuePair<string, object?>>)
@@ -185,7 +185,7 @@ private LogEventInfo CreateLogEventInfo<TState>(LogLevel nLogLogLevel, in EventI
185185
{
186186
if (_options.CaptureMessageProperties)
187187
{
188-
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
188+
#if NETSTANDARD2_1_OR_GREATER || NET
189189
var logEventWithoutBoxing = GetMessageParametersWithoutBoxing(nLogLogLevel, eventId, state, exception, formatter);
190190
if (logEventWithoutBoxing is not null)
191191
{
@@ -528,7 +528,7 @@ private void CaptureEventIdProperties(LogEventInfo logEvent, in EventId eventId)
528528
}
529529
}
530530

531-
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
531+
#if NETSTANDARD2_1_OR_GREATER || NET
532532
int GetEventIdMessageParameters(in EventId eventId, out MessageTemplateParameter arg1, out MessageTemplateParameter arg2)
533533
{
534534
var captureEventId = _options.CaptureEventId;

0 commit comments

Comments
 (0)