コード例 #1
0
        protected string ToColor(LogMessageEntry log)
        {
            // Colorize EF/Http differentely
            if (log.Message.StartsWith("Executed DbCommand "))
            {
                return("aqua");
            }

            if (log.Message.StartsWith("Sending HTTP request") ||
                log.Message.StartsWith("Received HTTP response"))
            {
                return("olive");
            }

            switch (log.LogLevel)
            {
            case LogLevel.Trace:
            case LogLevel.Debug:
                return("gray");

            case LogLevel.Warning:
                return("yellow");

            case LogLevel.Error:
            case LogLevel.Critical:
                return("red");

            case LogLevel.Information:
            case LogLevel.None:
            default:
                return("#fff");
            }
        }
コード例 #2
0
        internal async virtual void WriteMessage(LogMessageEntry message)
        {
            if (message.Remote == null)
            {
                await WriteLineAsync($"<div style='color:{ToColor(message)}'>{message.TimeStamp.ToString(_middleware._options.CurrentValue.TimestampFormat) + ": "}{ToHtml(message.Message)}</div>");

                if (message.Exception != null)
                {
                    await WriteLineAsync($"<div style='color:{ToColor(message)}'>{ToHtml(message.Exception.Message)}</div>");
                    await WriteLineAsync($"<div style='color:{ToStackTraceColor(message.LogLevel)}'>{ToHtml(message.Exception.ToString())}</div>");
                }
            }
            else
            {
                // Insert remote name inside message
                var msg = message.Message;
                int i   = msg.IndexOf('>');
                i = msg.IndexOf(' ', i);
                if (i >= 0)
                {
                    msg = msg.Insert(i + 1, message.Remote + ": ");
                }
                await WriteLineAsync(msg);
            }
        }
コード例 #3
0
 public void LogMessage(LogMessageEntry message)
 {
     for (int i = 0; i < _logProcessors.Count; i++)
     {
         if (_logProcessors[i].AcceptsMessage(message))
         {
             _logProcessors[i].EnqueueMessage(message);
         }
     }
 }
コード例 #4
0
        public virtual bool AcceptsMessage(LogMessageEntry message)
        {
            if (message.LogLevel < _logLevel)
            {
                return(false);
            }

            if (!string.IsNullOrEmpty(_key) && message.HttpLoggerKey != _key)
            {
                return(false);
            }

            return(true);
        }
コード例 #5
0
        public virtual bool AcceptsMessage(LogMessageEntry message)
        {
            if (message.LogLevel < _logLevel)
            {
                return(false);
            }

            if (!string.IsNullOrEmpty(_key) && message.HttpLoggerKey != _key)
            {
                return(false);
            }

            if (!string.IsNullOrEmpty(_user) && !string.Equals(message.User, _user, StringComparison.OrdinalIgnoreCase))
            {
                return(false);
            }

            return(true);
        }
コード例 #6
0
        public virtual void EnqueueMessage(LogMessageEntry message)
        {
            if (!_messageQueue.IsAddingCompleted)
            {
                try
                {
                    _messageQueue.Add(message);
                    return;
                }
                catch (InvalidOperationException) { }
            }

            // Adding is completed so just log the message
            try
            {
                WriteMessage(message);
            }
            catch (Exception) { }
        }
コード例 #7
0
        private void RemoteLog(object obj)
        {
            var remote = obj as Remote;

            using (var client = new HttpClient())
            {
                client.Timeout = TimeSpan.FromMilliseconds(Timeout.Infinite);

                var request = new HttpRequestMessage(HttpMethod.Get, remote.Url + _query);
                using (var response = client.SendAsync(
                           request,
                           HttpCompletionOption.ResponseHeadersRead).Result)
                {
                    using (var body = response.Content.ReadAsStreamAsync().Result)
                        using (var reader = new StreamReader(body))
                            while (!reader.EndOfStream)
                            {
                                var message = new LogMessageEntry(DateTime.Now, LogLevel.Debug, new EventId(0), null, reader.ReadLine(), null, remote.Name);
                                this.EnqueueMessage(message);
                            }
                }
            }
        }