DotLog.LogEntry.ToString C# (CSharp) Method

ToString() public method

public ToString ( ) : string
return string
        public override string ToString()
        {
            var sb = new StringBuilder();

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

            return sb.ToString();
        }

Same methods

LogEntry::ToString ( ILogFormatter formatter ) : string

Usage Example

Ejemplo n.º 1
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;
        }
LogEntry