void ExecuteTest(LeClient client) { client.Connect(); client.Write("605885c4-a4d4-42c7-a3f4-f2f97b124ca1" + " HTTPS test log entry\n"); client.Flush(); client.Close(); }
/// <summary> /// Emit a batch of log events, running to completion synchronously. /// </summary> /// <param name="events">The events to emit.</param> /// <remarks> /// Override either <see cref="M:Serilog.Sinks.PeriodicBatching.PeriodicBatchingSink.EmitBatch(System.Collections.Generic.IEnumerable{Serilog.Events.LogEvent})" /> or <see cref="M:Serilog.Sinks.PeriodicBatching.PeriodicBatchingSink.EmitBatchAsync(System.Collections.Generic.IEnumerable{Serilog.Events.LogEvent})" />, /// not both. /// </remarks> protected override void EmitBatch(IEnumerable <LogEvent> events) { if (events.Any() == false) { return; } try { if (_client == null) { _client = new LeClient(false, _useSsl); } _client.Connect(); } catch (Exception ex) { SelfLog.WriteLine("Unable to connect to Logentries API.", ex); return; } foreach (var logEvent in events) { var renderSpace = new StringWriter(); _textFormatter.Format(logEvent, renderSpace); var renderedString = renderSpace.ToString(); // LogEntries uses a NewLine character to determine the end of a log message // this causes problems with stack traces. if (!string.IsNullOrEmpty(renderedString)) { renderedString = renderedString.Replace("\n", ""); } var finalLine = _token + renderedString + '\n'; var data = UTF8.GetBytes(finalLine); _client.Write(data, 0, data.Length); } _client.Flush(); _client.Close(); }
/// <summary> /// Emit a batch of log events, running to completion synchronously. /// </summary> /// <param name="events">The events to emit.</param> /// <remarks> /// Override either <see cref="M:Serilog.Sinks.PeriodicBatching.PeriodicBatchingSink.EmitBatchAsync(System.Collections.Generic.IEnumerable{Serilog.Events.LogEvent})" /> or <see cref="M:Serilog.Sinks.PeriodicBatching.PeriodicBatchingSink.EmitBatchAsync(System.Collections.Generic.IEnumerable{Serilog.Events.LogEvent})" />, /// not both. /// </remarks> protected override async Task EmitBatchAsync(IEnumerable <LogEvent> events) { if (events.Any() == false) { await Task.FromResult(0); } if (_client == null) { _client = new LeClient(false, _useSsl, _url); } await _client.ConnectAsync().ConfigureAwait(false); foreach (var logEvent in events) { var renderSpace = new StringWriter(); _textFormatter.Format(logEvent, renderSpace); var renderedString = renderSpace.ToString(); // LogEntries uses a NewLine character to determine the end of a log message // this causes problems with stack traces. if (!string.IsNullOrEmpty(renderedString)) { renderedString = renderedString.Replace("\n", ""); } var finalLine = _token + renderedString + '\n'; var data = Utf8.GetBytes(finalLine); await _client.WriteAsync(data, 0, data.Length).ConfigureAwait(false); } await _client.FlushAsync().ConfigureAwait(false); _client.Close(); }
/// <summary> /// Emit a batch of log events, running to completion synchronously. /// </summary> /// <param name="events">The events to emit.</param> /// <remarks> /// Override either <see cref="M:Serilog.Sinks.PeriodicBatching.PeriodicBatchingSink.EmitBatch(System.Collections.Generic.IEnumerable{Serilog.Events.LogEvent})" /> or <see cref="M:Serilog.Sinks.PeriodicBatching.PeriodicBatchingSink.EmitBatchAsync(System.Collections.Generic.IEnumerable{Serilog.Events.LogEvent})" />, /// not both. /// </remarks> protected override void EmitBatch(IEnumerable <LogEvent> events) { if (events.Any() == false) { return; } try { if (_client == null) { _client = new LeClient(false, _useSsl); } _client.Connect(); } catch (Exception ex) { SelfLog.WriteLine("Unable to connect to Logentries API.", ex); return; } foreach (var logEvent in events) { var renderSpace = new StringWriter(); _textFormatter.Format(logEvent, renderSpace); var finalLine = _token + renderSpace.ToString() + '\n'; byte[] data = UTF8.GetBytes(finalLine); _client.Write(data, 0, data.Length); } _client.Flush(); _client.Close(); }
/// <summary> /// Emit a batch of log events, running to completion synchronously. /// </summary> /// <param name="events">The events to emit.</param> /// <remarks> /// Override either <see cref="M:Serilog.Sinks.PeriodicBatching.PeriodicBatchingSink.EmitBatch(System.Collections.Generic.IEnumerable{Serilog.Events.LogEvent})" /> or <see cref="M:Serilog.Sinks.PeriodicBatching.PeriodicBatchingSink.EmitBatchAsync(System.Collections.Generic.IEnumerable{Serilog.Events.LogEvent})" />, /// not both. /// </remarks> protected override void EmitBatch(IEnumerable<LogEvent> events) { if (events.Any() == false) return; if (_client == null) _client = new LeClient(false, _useSsl); _client.Connect(); foreach (var logEvent in events) { var renderSpace = new StringWriter(); _textFormatter.Format(logEvent, renderSpace); var renderedString = renderSpace.ToString(); // LogEntries uses a NewLine character to determine the end of a log message // this causes problems with stack traces. if (!string.IsNullOrEmpty(renderedString)) renderedString = renderedString.Replace("\n", ""); var finalLine = _token + renderedString + '\n'; var data = UTF8.GetBytes(finalLine); _client.Write(data, 0, data.Length); } _client.Flush(); _client.Close(); }
/// <summary> /// Emit a batch of log events, running to completion synchronously. /// </summary> /// <param name="events">The events to emit.</param> /// <remarks> /// Override either <see cref="M:Serilog.Sinks.PeriodicBatching.PeriodicBatchingSink.EmitBatch(System.Collections.Generic.IEnumerable{Serilog.Events.LogEvent})" /> or <see cref="M:Serilog.Sinks.PeriodicBatching.PeriodicBatchingSink.EmitBatchAsync(System.Collections.Generic.IEnumerable{Serilog.Events.LogEvent})" />, /// not both. /// </remarks> protected override void EmitBatch(IEnumerable<LogEvent> events) { if (events.Any() == false) return; try { if (_client == null) _client = new LeClient(false, _useSsl); _client.Connect(); } catch (Exception ex) { SelfLog.WriteLine("Unable to connect to Logentries API.", ex); return; } foreach (var logEvent in events) { var renderSpace = new StringWriter(); _textFormatter.Format(logEvent, renderSpace); var finalLine = _token + renderSpace.ToString() + '\n'; byte[] data = UTF8.GetBytes(finalLine); _client.Write(data, 0, data.Length); } _client.Flush(); _client.Close(); }
public void TestTcpTokenWriteHttps() { var client = new LeClient(false, true); ExecuteTest(client); }
public void TestHttpPutWriteHttps() { var client = new LeClient(true, true, accountKey: "", hostKey:"General Tests", logKey: ""); ExecuteTest(client); }