Dreamine.Logging 1.0.2
Dreamine.Logging 프로젝트의 API와 구성 요소를 제공합니다.
로딩중...
검색중...
일치하는것 없음
CompositeLogSink.cs
이 파일의 문서화 페이지로 가기
1using System;
2using System.Collections.Generic;
3using System.Linq;
6
8{
25 public sealed class CompositeLogSink : IDreamineLogSink, IDisposable
26 {
35 private readonly IReadOnlyList<IDreamineLogSink> _sinks;
44 private bool _disposed;
45
78 public CompositeLogSink(IEnumerable<IDreamineLogSink> sinks)
79 {
80 ArgumentNullException.ThrowIfNull(sinks);
81
82 _sinks = sinks.ToArray();
83
84 if (_sinks.Count == 0)
85 {
86 throw new ArgumentException("At least one log sink is required.", nameof(sinks));
87 }
88 }
89
114 public void Write(DreamineLogEntry entry)
115 {
116 ArgumentNullException.ThrowIfNull(entry);
117
118 if (_disposed)
119 {
120 return;
121 }
122
123 foreach (var sink in _sinks)
124 {
125 try
126 {
127 sink.Write(entry);
128 }
129 catch
130 {
131 // Logging failure must not terminate the application.
132 }
133 }
134 }
135
144 public void Dispose()
145 {
146 if (_disposed)
147 {
148 return;
149 }
150
151 _disposed = true;
152
153 foreach (var sink in _sinks)
154 {
155 if (sink is IDisposable disposable)
156 {
157 try
158 {
159 disposable.Dispose();
160 }
161 catch
162 {
163 // Logging dispose failure must not terminate the application.
164 }
165 }
166 }
167 }
168 }
169}
readonly IReadOnlyList< IDreamineLogSink > _sinks
CompositeLogSink(IEnumerable< IDreamineLogSink > sinks)