/// <summary> /// Construct a new <see cref="LogEvent"/>. /// </summary> public static string Serialize(Events.LogEvent logEvent, string renderedMessage) { var e = new SimplifiedLogEvent() { Timestamp = logEvent.Timestamp, Exception = logEvent.Exception, MessageTemplate = logEvent.MessageTemplate.Text, Level = logEvent.Level, RenderedMessage = renderedMessage, Properties = new Dictionary <string, object>() }; foreach (var pair in logEvent.Properties) { e.Properties.Add(pair.Key, SimplifyPropertyFormatter.Simplify(pair.Value)); } return(Newtonsoft.Json.JsonConvert.SerializeObject(e)); }
private void ConnectionLifetime() { while (true) { ReadyToEmit = false; using (NamedPipeServerStream pipe = new NamedPipeServerStream(_pipeName)) { pipe.WaitForConnection(); ReadyToEmit = true; try { using (var _pipeWriter = new StreamWriter(pipe, _encoding) { AutoFlush = true }) { while (true) { while (!m_Queue.IsCompleted) { var i = m_Queue.Take(); var json = SimplifiedLogEvent.Serialize(i, i.RenderMessage()); _pipeWriter.WriteLine(json); } Thread.Sleep(10); } } } // Catch the IOException that is raised if the pipe is broken or disconnected. catch (IOException) { ReadyToEmit = false; } catch (Exception) { } } } }