public void Write(TraceEventType level, Action <LogDelegate> log, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0, [CallerMemberName] string method = null) { if (MinimumTraceLevel < level) { return; } var logCallSiteInfo = new LogCallSiteInfo { ReflectedType = CallSiteInfoTemplate?.ReflectedType, ClassName = CallSiteInfoTemplate?.ClassName, AssemblyName = CallSiteInfoTemplate?.AssemblyName, AssemblyVersion = CallSiteInfoTemplate?.AssemblyVersion, MethodName = method, FileName = file, LineNumber = line, BuildTime = CallSiteInfoTemplate?.BuildTime }; try { log((message, encryptedTags, unencryptedTags, exception, includeStack) => { var stackTrace = includeStack ? Environment.StackTrace : null; //Some time people make mistake between encryptedTags and exception fields. if (encryptedTags is Exception && exception == null) { exception = (Exception)encryptedTags; encryptedTags = null; } var unencTags = TagsExtractor.GetTagsFromObject(unencryptedTags) .Concat(exception.GetUnencryptedTags()) .Where(_ => _.Value != null) .FormatTagsWithTypeSuffix() .ToDictionary(kvp => kvp.Key, kvp => kvp.Value); var encTags = TagsExtractor.GetTagsFromObject(encryptedTags) .Concat(exception.GetEncryptedTagsAndExtendedProperties()) .Where(_ => _.Value != null) .FormatTagsWithoutTypeSuffix() .ToDictionary(kvp => kvp.Key, kvp => kvp.Value); WriteLog(level, logCallSiteInfo, message, encTags, unencTags, exception, stackTrace); }); } catch (Exception ex) { Trace.TraceError($"Programmatic error while logging: {ex}"); } }
protected abstract Task <bool> WriteLog(TraceEventType level, LogCallSiteInfo logCallSiteInfo, string message, IDictionary <string, string> encryptedTags, IDictionary <string, string> unencryptedTags, Exception exception = null, string stackTrace = null);