Exemplo n.º 1
0
        public void Write(TraceEventType level, Action <LogDelegate> log, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0, [CallerMemberName] string method = null)
        {
            TryConfigureUpdatingOfLogLevel(log);

            if (MinimumTraceLevel < level)
            {
                return;
            }

            var logCallSiteInfo = new LogCallSiteInfo
            {
                LoggerName      = CallSiteInfoTemplate?.LoggerName,
                Namespace       = CallSiteInfoTemplate?.Namespace,
                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 = RemoveDuplicatesTag(TagsExtractor.GetTagsFromObject(unencryptedTags)
                                                        .Concat(exception.GetUnencryptedTags())
                                                        .Where(_ => _.Value != null)
                                                        .FormatTagsWithTypeSuffix()
                                                        );

                    var encTags = RemoveDuplicatesTag(TagsExtractor.GetTagsFromObject(encryptedTags)
                                                      .Concat(exception.GetEncryptedTagsAndExtendedProperties())
                                                      .Where(_ => _.Value != null)
                                                      .FormatTagsWithoutTypeSuffix());


                    WriteLog(level, logCallSiteInfo, message, encTags, unencTags, exception, stackTrace);
                });
            }
            catch (Exception ex)
            {
                Trace.TraceError($"Programmatic error while logging: {ex}");
            }
        }
Exemplo n.º 2
0
 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);