Dreamine.Logging 1.0.2
Dreamine.Logging 프로젝트의 API와 구성 요소를 제공합니다.
로딩중...
검색중...
일치하는것 없음
DreamineLogger.cs
이 파일의 문서화 페이지로 가기
1using System;
4
6
15public sealed class DreamineLogger : IDreamineLogger
16{
25 private readonly IReadOnlyList<IDreamineLogSink> _sinks;
43 private readonly string _category;
44
62 : this(new[] { sink }, DreamineLogLevel.Trace, "Dreamine")
63 {
64 }
65
90 public DreamineLogger(IDreamineLogSink sink, string category)
91 : this(new[] { sink }, DreamineLogLevel.Trace, category)
92 {
93 }
94
136 IDreamineLogSink sink,
137 DreamineLogLevel minimumLevel,
138 string category)
139 : this(new[] { sink }, minimumLevel, category)
140 {
141 }
142
192 IEnumerable<IDreamineLogSink> sinks,
193 DreamineLogLevel minimumLevel = DreamineLogLevel.Trace,
194 string category = "Dreamine")
195 {
196 if (sinks is null)
197 {
198 throw new ArgumentNullException(nameof(sinks));
199 }
200
201 _sinks = sinks.ToArray();
202
203 if (_sinks.Count == 0)
204 {
205 throw new ArgumentException("At least one log sink is required.", nameof(sinks));
206 }
207
208 _minimumLevel = minimumLevel;
209 _category = string.IsNullOrWhiteSpace(category) ? "Dreamine" : category;
210 }
211
228 public void Trace(string message) => Write(DreamineLogLevel.Trace, message, null);
229
246 public void Debug(string message) => Write(DreamineLogLevel.Debug, message, null);
247
264 public void Info(string message) => Write(DreamineLogLevel.Info, message, null);
265
282 public void Warning(string message) => Write(DreamineLogLevel.Warning, message, null);
283
300 public void Error(string message) => Write(DreamineLogLevel.Error, message, null);
301
326 public void Error(Exception exception, string message) => Write(DreamineLogLevel.Error, message, exception);
327
344 public void Fatal(string message) => Write(DreamineLogLevel.Fatal, message, null);
345
370 public void Fatal(Exception exception, string message) => Write(DreamineLogLevel.Fatal, message, exception);
371
396 public void Write(DreamineLogEntry entry)
397 {
398 if (entry is null)
399 {
400 throw new ArgumentNullException(nameof(entry));
401 }
402
403 if (entry.Level < _minimumLevel)
404 {
405 return;
406 }
407
408 foreach (var sink in _sinks)
409 {
410 try
411 {
412 sink.Write(entry);
413 }
414 catch
415 {
416 // Logging failure must not terminate the application.
417 }
418 }
419 }
420
453 private void Write(DreamineLogLevel level, string message, Exception? exception)
454 {
455 var entry = new DreamineLogEntry(
456 DateTimeOffset.Now,
457 level,
458 _category,
459 message,
460 exception,
461 Environment.CurrentManagedThreadId);
462
463 Write(entry);
464 }
465}
void Fatal(Exception exception, string message)
DreamineLogger(IDreamineLogSink sink, string category)
DreamineLogger(IDreamineLogSink sink, DreamineLogLevel minimumLevel, string category)
DreamineLogger(IEnumerable< IDreamineLogSink > sinks, DreamineLogLevel minimumLevel=DreamineLogLevel.Trace, string category="Dreamine")
readonly IReadOnlyList< IDreamineLogSink > _sinks
void Error(Exception exception, string message)
void Write(DreamineLogLevel level, string message, Exception? exception)
void Write(DreamineLogEntry entry)
readonly DreamineLogLevel _minimumLevel