internal bool TryRememberCallSiteClassName(LogEventInfo logEvent) { if (string.IsNullOrEmpty(logEvent.CallSiteInformation?.CallerFilePath)) { return(false); } string className = logEvent.CallSiteInformation.GetCallerClassName(null, true, true, true); if (string.IsNullOrEmpty(className)) { return(false); } if (_callSiteClassNameCache == null) { return(false); } string internClassName = logEvent.LoggerName == className ? logEvent.LoggerName : #if !NETSTANDARD1_3 && !NETSTANDARD1_5 string.Intern(className); // Single string-reference for all logging-locations for the same class #else className; #endif CallSiteKey callSiteKey = new CallSiteKey(logEvent.CallerMemberName, logEvent.CallerFilePath, logEvent.CallerLineNumber); return(_callSiteClassNameCache.TryAddValue(callSiteKey, internClassName)); }
internal bool TryLookupCallSiteClassName(LogEventInfo logEvent, out string callSiteClassName) { callSiteClassName = logEvent.CallSiteInformation?.CallerClassName; if (!string.IsNullOrEmpty(callSiteClassName)) { return(true); } if (_callSiteClassNameCache == null) { System.Threading.Interlocked.CompareExchange(ref _callSiteClassNameCache, new MruCache <CallSiteKey, string>(1000), null); } CallSiteKey callSiteKey = new CallSiteKey(logEvent.CallerMemberName, logEvent.CallerFilePath, logEvent.CallerLineNumber); return(_callSiteClassNameCache.TryGetValue(callSiteKey, out callSiteClassName)); }