Exemplo n.º 1
0
        public LogDetails Add(string key, object value)
        {
            if (Details.TryGetValue(key, out _))
            {
                if (Details[key] != value)
                {
                    Details[key] = value;
                }
                else
                {
                    var details = new LogDetails();
                    details.Add("StackTrace", Environment.StackTrace);
                    details.Add("Key", key);
                    details.Add("Value", value);

                    Logger.Log()?.Warn("Tried to insert duplicate key to log details!", null, details);
                }
            }
            else
            {
                Details.Add(key, value);
            }

            return(this);
        }
Exemplo n.º 2
0
        public void Log(string message, BaseLogType baseLogType, LogLevel logLevel, LogDetails details = null, Exception ex = null, string memberName = "",
                        string sourceFilePath = "", int sourceLineNumber = 0)
        {
            details ??= new LogDetails();

            //add possible exception and info about where the log was written into the logDetails
            details.Add(LogMetadataFieldNames.MemberName, memberName)
            .Add(LogMetadataFieldNames.SourceFilePath, sourceFilePath)
            .Add(LogMetadataFieldNames.SourceLineNumber, sourceLineNumber);

            if (ex != null)
            {
                details.Add(LogMetadataFieldNames.Exception, ex);
            }

            Log(message, baseLogType, details, logLevel);
        }