Exemple #1
0
        public string Format(LogEntry logEntry)
        {
            if (FormatSpecification == null)
            {
                FormatSpecification = new FormatSpecification
                {
                    Template = DefaultTemplate,
                };
            }

            // TODO add real support for using the template
            var sb = new StringBuilder();

            sb.AppendFormat("[{0}][{1}][{2}] {3}",
                logEntry.Timestamp.ToUniversalTime(),
                logEntry.LogLevel,
                logEntry.Category,
                logEntry.Message);

            return sb.ToString();
        }
Exemple #2
0
        /// <summary>
        ///   Write the log entry to the output destination.
        /// </summary>
        /// <param name="message"> Must not be null or empty </param>
        /// <param name="logLevel"> </param>
        /// <param name="category"> </param>
        /// <returns> </returns>
        public virtual LogEntry Log(string message, LogLevel logLevel = LogLevel.Verbose, string category = null)
        {
            if (string.IsNullOrWhiteSpace(message))
            {
                throw new ArgumentNullException("message");
            }

            var logEntry = new LogEntry
            {
                Timestamp = DateTime.UtcNow,
                Message = message,
                LogLevel = logLevel,
                Category = category,
            };

            if (LogAction != null && logLevel != LogLevel.None && logLevel >= LogLevel)
            {
                // if Formatter is null, generates a default formatted string
                var output = logEntry.ToString(Formatter);

                LogAction(output);
            }

            return logEntry;
        }