public void EnqueuedEntriesAreDequedFifo() { using (var temp = TempFolder.ForCaller()) using (var buffer = new LogBuffer(temp.AllocateFilename("mdb"), DefaultBufferSize)) { byte[] a1 = Some.Bytes(140), a2 = Some.Bytes(140), a3 = Some.Bytes(140); buffer.Enqueue(new[] { a1, a2 }); buffer.Enqueue(new[] { a3 }); var contents = buffer.Peek((int)DefaultBufferSize); Assert.Equal(3, contents.Length); Assert.Equal(a1, contents[0].Value); Assert.Equal(a2, contents[1].Value); Assert.Equal(a3, contents[2].Value); } }
public void GivingTheLastSeeEventKeyLeavesSuccessiveEvents() { using (var temp = TempFolder.ForCaller()) using (var buffer = new LogBuffer(temp.AllocateFilename("mdb"), DefaultBufferSize)) { byte[] a1 = Some.Bytes(140), a2 = Some.Bytes(140), a3 = Some.Bytes(140); buffer.Enqueue(new[] { a1, a2, a3 }); var contents = buffer.Peek(30); Assert.Equal(1, contents.Length); buffer.Enqueue(new [] { Some.Bytes(140) }); buffer.Dequeue(contents[0].Key); var remaining = buffer.Peek(420); Assert.Equal(3, remaining.Length); } }
private static void ConfigureGlobalLogger() { Serilog.Log.Logger = (OptionsAtStartup.Debug ? new LoggerConfiguration().MinimumLevel.Debug() : new LoggerConfiguration().MinimumLevel.Information()) .MinimumLevel.Override("Microsoft", LogEventLevel.Error) .MinimumLevel.Override("System.Net.Http.HttpClient", OptionsAtStartup.Debug ? LogEventLevel.Warning : LogEventLevel.Fatal) .MinimumLevel.Override("slskd.Authentication.PassthroughAuthenticationHandler", LogEventLevel.Warning) .Enrich.WithProperty("InstanceName", OptionsAtStartup.InstanceName) .Enrich.WithProperty("InvocationId", InvocationId) .Enrich.WithProperty("ProcessId", ProcessId) .Enrich.FromLogContext() .WriteTo.Console( outputTemplate: (OptionsAtStartup.Debug ? "[{SubContext}] " : string.Empty) + "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}") .WriteTo.Async(config => config.File( Path.Combine(AppDirectory, "logs", $"{AppName}-.log"), outputTemplate: (OptionsAtStartup.Debug ? "[{SubContext}] " : string.Empty) + "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}", rollingInterval: RollingInterval.Day)) .WriteTo.Conditional( e => !string.IsNullOrEmpty(OptionsAtStartup.Logger.Loki), config => config.GrafanaLoki( OptionsAtStartup.Logger.Loki ?? string.Empty, outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}")) .WriteTo.Sink(new DelegatingSink(logEvent => { try { var message = logEvent.RenderMessage(); if (logEvent.Exception != null) { message = $"{message}: {logEvent.Exception}"; } var record = new LogRecord() { Timestamp = logEvent.Timestamp.LocalDateTime, Context = logEvent.Properties["SourceContext"].ToString().TrimStart('"').TrimEnd('"'), SubContext = logEvent.Properties.ContainsKey("SubContext") ? logEvent.Properties["SubContext"].ToString().TrimStart('"').TrimEnd('"') : null, Level = logEvent.Level.ToString(), Message = message.TrimStart('"').TrimEnd('"'), }; LogBuffer.Enqueue(record); LogEmitted?.Invoke(null, record); } catch (Exception ex) { Log.Information($"Misconfigured delegating logger: {ex.Message}"); } })) .CreateLogger(); }
public void AtLeastOneEventIsAlwaysDequeued() { using (var temp = TempFolder.ForCaller()) using (var buffer = new LogBuffer(temp.AllocateFilename("mdb"), DefaultBufferSize)) { byte[] a1 = Some.Bytes(140), a2 = Some.Bytes(140), a3 = Some.Bytes(140); buffer.Enqueue(new[] { a1, a2, a3 }); var contents = buffer.Peek(30); Assert.Equal(1, contents.Length); Assert.Equal(a1, contents[0].Value); } }
public void PeekingDoesNotChangeState() { using (var temp = TempFolder.ForCaller()) using (var buffer = new LogBuffer(temp.AllocateFilename("mdb"), DefaultBufferSize)) { buffer.Enqueue(new[] { Some.Bytes(140) }); var contents = buffer.Peek((int)DefaultBufferSize); Assert.Equal(1, contents.Length); var remainder = buffer.Peek((int)DefaultBufferSize); Assert.Equal(1, remainder.Length); } }
public void SizeHintLimitsDequeuedEventCount() { using (var temp = TempFolder.ForCaller()) using (var buffer = new LogBuffer(temp.AllocateFilename("mdb"), DefaultBufferSize)) { byte[] a1 = Some.Bytes(140), a2 = Some.Bytes(140), a3 = Some.Bytes(140); buffer.Enqueue(new[] { a1, a2, a3 }); var contents = buffer.Peek(300); Assert.Equal(2, contents.Length); Assert.Equal(a1, contents[0].Value); Assert.Equal(a2, contents[1].Value); } }
public void EnumerationIsInOrder() { using (var temp = TempFolder.ForCaller()) using (var buffer = new LogBuffer(temp.AllocateFilename("mdb"), DefaultBufferSize)) { byte[] a1 = Some.Bytes(140), a2 = Some.Bytes(140), a3 = Some.Bytes(140); buffer.Enqueue(new[] { a1, a2, a3 }); var contents = new List <byte[]>(); buffer.Enumerate((k, v) => { contents.Add(v); }); Assert.Equal(3, contents.Count); Assert.Equal(new[] { a1, a2, a3 }, contents); } }