Exemplo n.º 1
0
 public void SetFormat(GRYLogLogFormat format)
 {
     foreach (GRYLogTarget target in this.LogTargets)
     {
         target.Format = format;
     }
 }
Exemplo n.º 2
0
        private void FormatMessage(GRYLogConfiguration configuration, string message, DateTime momentOfLogEntry, LogLevel loglevel, GRYLogLogFormat format, out string formattedMessage, out int colorBegin, out int colorEnd, out ConsoleColor consoleColor, string messageIdValue)
        {
            consoleColor = configuration.GetLoggedMessageTypesConfigurationByLogLevel(loglevel).ConsoleColor;
            if (!string.IsNullOrEmpty(configuration.Name))
            {
                message = $"[{configuration.Name.Trim()}] {message}";
            }
            if (configuration.ConvertTimeForLogentriesToUTCFormat)
            {
                momentOfLogEntry = momentOfLogEntry.ToUniversalTime();
            }
            switch (format)
            {
            case GRYLogLogFormat.OnlyMessage:
                formattedMessage = message;
                colorBegin       = 0;
                colorEnd         = 0;
                break;

            case GRYLogLogFormat.GRYLogFormat:
                string messageId;
                if (string.IsNullOrWhiteSpace(messageIdValue))
                {
                    messageId = string.Empty;
                }
                else
                {
                    messageId = $"[{messageIdValue}] ";
                }
                string part1 = $"[{momentOfLogEntry.ToString(configuration.DateFormat)}] {messageId}[";
                string part2 = configuration.GetLoggedMessageTypesConfigurationByLogLevel(loglevel).CustomText;
                string part3 = "] " + message;
                formattedMessage = part1 + part2 + part3;
                colorBegin       = part1.Length;
                colorEnd         = part1.Length + part2.Length;
                break;

            case GRYLogLogFormat.DateOnly:
                formattedMessage = momentOfLogEntry.ToString(configuration.DateFormat) + " " + message;
                colorBegin       = 0;
                colorEnd         = 0;
                break;

            default:
                throw new KeyNotFoundException($"Formatting {nameof(GRYLogLogFormat)} '{loglevel}' is not implemented yet.");
            }
        }
Exemplo n.º 3
0
 internal void Format(GRYLogConfiguration configuration, out string formattedMessage, out int colorBegin, out int colorEnd, out ConsoleColor consoleColor, GRYLogLogFormat format, string messageIdValue)
 {
     if (!this._FormatingLoaded)
     {
         this.FormatMessage(configuration, this.PlainMessage, this.MomentOfLogEntry, this.LogLevel, format, out string fm, out int cb, out int ce, out ConsoleColor cc, messageIdValue);
         this._FormattedMessage = fm;
         this._ColorBegin       = cb;
         this._ColorEnd         = ce;
         this._ConsoleColor     = cc;
         this._FormatingLoaded  = true;
     }
     formattedMessage = this._FormattedMessage;
     colorBegin       = this._ColorBegin;
     colorEnd         = this._ColorEnd;
     consoleColor     = this._ConsoleColor;
 }