Dreamine.Logging 1.0.2
Dreamine.Logging 프로젝트의 API와 구성 요소를 제공합니다.
로딩중...
검색중...
일치하는것 없음
DreamineLoggingRegistration.cs
이 파일의 문서화 페이지로 가기
1using System;
8using Dreamine.MVVM.Core;
9
11
20public static class DreamineLoggingRegistration
21{
46 public static IAsyncDisposable Register(Action<DreamineLoggingOptions>? configure = null)
47 {
48 var options = new DreamineLoggingOptions();
49 configure?.Invoke(options);
50
51 return Register(options);
52 }
53
86 public static IAsyncDisposable Register(DreamineLoggingOptions options)
87 {
88 ArgumentNullException.ThrowIfNull(options);
89
90 var logStore = new InMemoryLogStore(options.StoreCapacity);
91 var formatter = new DreamineTextLogFormatter();
92
93 var textFileSink = new TextFileLogSink(
94 options.LogDirectory,
95 formatter,
96 options.FlushEveryWriteCount);
97
98 var compositeSink = new CompositeLogSink(new IDreamineLogSink[]
99 {
100 logStore,
101 textFileSink
102 });
103
104 var asyncSink = new AsyncQueueSink(
105 compositeSink,
106 options.QueueCapacity,
107 options.DrainBatchSize);
108
109 var logger = new DreamineLogger(
110 new IDreamineLogSink[] { asyncSink },
111 DreamineLogLevel.Trace,
112 options.Category);
113
114 DMContainer.RegisterSingleton(logStore);
115 DMContainer.RegisterSingleton<IDreamineLogStore>(logStore);
116 DMContainer.RegisterSingleton<IDreamineLogFormatter>(formatter);
117 DMContainer.RegisterSingleton(asyncSink);
118 DMContainer.RegisterSingleton<IDreamineLogSink>(asyncSink);
119 DMContainer.RegisterSingleton<IDreamineLogger>(logger);
120
121 return new LoggingShutdownHandle(asyncSink, options.ShutdownTimeout);
122 }
123
132 private sealed class LoggingShutdownHandle : IAsyncDisposable
133 {
142 private readonly AsyncQueueSink _asyncSink;
151 private readonly TimeSpan _shutdownTimeout;
152
177 public LoggingShutdownHandle(AsyncQueueSink asyncSink, TimeSpan shutdownTimeout)
178 {
179 _asyncSink = asyncSink;
180 _shutdownTimeout = shutdownTimeout;
181 }
182
199 public async ValueTask DisposeAsync()
200 {
201 await _asyncSink.ShutdownAsync(_shutdownTimeout).ConfigureAwait(false);
202 }
203 }
204}
static IAsyncDisposable Register(DreamineLoggingOptions options)
static IAsyncDisposable Register(Action< DreamineLoggingOptions >? configure=null)