3939#pragma warning disable 1591
4040
4141using System . Diagnostics . CodeAnalysis ;
42+ using System . Linq ;
4243
4344[ assembly: SuppressMessage ( "Microsoft.Design" , "CA1020:AvoidNamespacesWithFewTypes" , Scope = "namespace" , Target = "NEventSocket.Logging" ) ]
4445[ assembly: SuppressMessage ( "Microsoft.Design" , "CA1026:DefaultParametersShouldNotBeUsed" , Scope = "member" , Target = "NEventSocket.Logging.Logger.#Invoke(NEventSocket.Logging.LogLevel,System.Func`1<System.String>,System.Exception,System.Object[])" ) ]
@@ -508,16 +509,21 @@ static ILog For<T>()
508509#endif
509510 static ILog GetCurrentClassLogger ( )
510511 {
512+ #if NETSTANDARD16
513+ var trace = new StackTrace ( null , false ) ;
514+ var stackFrame = trace . GetFrames ( ) . Skip ( 1 ) . First ( ) ;
515+ #else
511516 var stackFrame = new StackFrame ( 1 , false ) ;
517+ #endif
512518 return GetLogger ( stackFrame . GetMethod ( ) . DeclaringType ) ;
513519 }
514520#endif
515521
516- /// <summary>
517- /// Gets a logger for the specified type.
518- /// </summary>
519- /// <param name="type">The type whose name will be used for the logger.</param>
520- /// <returns>An instance of <see cref="ILog"/></returns>
522+ /// <summary>
523+ /// Gets a logger for the specified type.
524+ /// </summary>
525+ /// <param name="type">The type whose name will be used for the logger.</param>
526+ /// <returns>An instance of <see cref="ILog"/></returns>
521527#if LIBLOG_PUBLIC
522528 public
523529#else
@@ -690,6 +696,7 @@ public bool Log(LogLevel logLevel, Func<string> messageFunc, Exception exception
690696 return false ;
691697 }
692698#if ! LIBLOG_PORTABLE
699+
693700 var envVar = Environment . GetEnvironmentVariable ( LogProvider . DisableLoggingEnvironmentVariable ) ;
694701
695702 if ( envVar != null && envVar . Equals ( "true" , StringComparison . OrdinalIgnoreCase ) )
@@ -1205,9 +1212,24 @@ public bool Log(LogLevel logLevel, Func<string> messageFunc, Exception exception
12051212 lock ( CallerStackBoundaryTypeSync )
12061213 {
12071214#if ! LIBLOG_PORTABLE
1215+ #if NETSTANDARD16
1216+ StackTrace stack = new StackTrace ( exception , true ) ;
1217+ #else
12081218 StackTrace stack = new StackTrace ( ) ;
1219+ #endif
12091220 Type thisType = GetType ( ) ;
12101221 s_callerStackBoundaryType = Type . GetType ( "LoggerExecutionWrapper" ) ;
1222+ #if NETSTANDARD16
1223+ var frames = stack . GetFrames ( ) ;
1224+ for ( var i = 1 ; i < frames . Length ; i ++ )
1225+ {
1226+ if ( ! IsInTypeHierarchy ( thisType , frames [ i ] . GetMethod ( ) . DeclaringType ) )
1227+ {
1228+ s_callerStackBoundaryType = frames [ i - 1 ] . GetMethod ( ) . DeclaringType ;
1229+ break ;
1230+ }
1231+ }
1232+ #else
12111233 for ( var i = 1 ; i < stack . FrameCount ; i ++ )
12121234 {
12131235 if ( ! IsInTypeHierarchy ( thisType , stack . GetFrame ( i ) . GetMethod ( ) . DeclaringType ) )
@@ -1216,6 +1238,7 @@ public bool Log(LogLevel logLevel, Func<string> messageFunc, Exception exception
12161238 break ;
12171239 }
12181240 }
1241+ #endif
12191242#else
12201243 s_callerStackBoundaryType = typeof ( LoggerExecutionWrapper ) ;
12211244#endif
@@ -1996,8 +2019,12 @@ internal static Type GetBaseTypePortable(this Type type)
19962019 {
19972020#if LIBLOG_PORTABLE
19982021 return type . GetTypeInfo ( ) . BaseType ;
2022+ #else
2023+ #if NETSTANDARD16
2024+ return type . GetTypeInfo ( ) . BaseType ;
19992025#else
20002026 return type . BaseType ;
2027+ #endif
20012028#endif
20022029 }
20032030
@@ -2016,16 +2043,24 @@ internal static MethodInfo GetSetMethod(this PropertyInfo propertyInfo)
20162043#if ! LIBLOG_PORTABLE
20172044 internal static object CreateDelegate ( this MethodInfo methodInfo , Type delegateType )
20182045 {
2046+ #if NETSTANDARD16
2047+ return null ;
2048+ #else
20192049 return Delegate . CreateDelegate ( delegateType , methodInfo ) ;
2050+ #endif
20202051 }
20212052#endif
20222053
20232054 internal static Assembly GetAssemblyPortable ( this Type type )
20242055 {
20252056#if LIBLOG_PORTABLE
20262057 return type . GetTypeInfo ( ) . Assembly ;
2058+ #else
2059+ #if NETSTANDARD16
2060+ return type . GetTypeInfo ( ) . Assembly ;
20272061#else
20282062 return type . Assembly ;
2063+ #endif
20292064#endif
20302065 }
20312066 }
0 commit comments