1- using System ;
2- using System . ComponentModel ;
1+ // Copyright © Serilog Contributors
2+ //
3+ // Licensed under the Apache License, Version 2.0 (the "License");
4+ // you may not use this file except in compliance with the License.
5+ // You may obtain a copy of the License at
6+ //
7+ // http://www.apache.org/licenses/LICENSE-2.0
8+ //
9+ // Unless required by applicable law or agreed to in writing, software
10+ // distributed under the License is distributed on an "AS IS" BASIS,
11+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ // See the License for the specific language governing permissions and
13+ // limitations under the License.
14+
15+ using System ;
316using Serilog . Configuration ;
417using Serilog . Sinks . Async ;
5- using Serilog . Events ;
618
7- namespace Serilog
19+ namespace Serilog ;
20+
21+ /// <summary>
22+ /// Extends <see cref="LoggerConfiguration"/> with methods for configuring asynchronous logging.
23+ /// </summary>
24+ public static class LoggerConfigurationAsyncExtensions
825{
926 /// <summary>
10- /// Extends <see cref="LoggerConfiguration"/> with methods for configuring asynchronous logging.
27+ /// Configure a sink to be invoked asynchronously, on a background worker thread.
28+ /// Accepts a reference to a <paramref name="monitor"/> that will be supplied the internal state interface for health monitoring purposes.
1129 /// </summary>
12- public static class LoggerConfigurationAsyncExtensions
30+ /// <param name="loggerSinkConfiguration">The <see cref="LoggerSinkConfiguration"/> being configured.</param>
31+ /// <param name="configure">An action that configures the wrapped sink.</param>
32+ /// <param name="bufferSize">The size of the concurrent queue used to feed the background worker thread. If
33+ /// the thread is unable to process events quickly enough and the queue is filled, depending on
34+ /// <paramref name="blockWhenFull"/> the queue will block or subsequent events will be dropped until
35+ /// room is made in the queue.</param>
36+ /// <param name="blockWhenFull">Block when the queue is full, instead of dropping events.</param>
37+ /// <param name="monitor">Monitor to supply buffer information to.</param>
38+ /// <returns>A <see cref="LoggerConfiguration"/> allowing configuration to continue.</returns>
39+ public static LoggerConfiguration Async (
40+ this LoggerSinkConfiguration loggerSinkConfiguration ,
41+ Action < LoggerSinkConfiguration > configure ,
42+ int bufferSize = 10000 ,
43+ bool blockWhenFull = false ,
44+ IAsyncLogEventSinkMonitor ? monitor = null )
1345 {
14- /// <summary>
15- /// Configure a sink to be invoked asynchronously, on a background worker thread.
16- /// </summary>
17- /// <param name="loggerSinkConfiguration">The <see cref="LoggerSinkConfiguration"/> being configured.</param>
18- /// <param name="configure">An action that configures the wrapped sink.</param>
19- /// <param name="bufferSize">The size of the concurrent queue used to feed the background worker thread. If
20- /// the thread is unable to process events quickly enough and the queue is filled, subsequent events will be
21- /// dropped until room is made in the queue.</param>
22- /// <returns>A <see cref="LoggerConfiguration"/> allowing configuration to continue.</returns>
23- [ EditorBrowsable ( EditorBrowsableState . Never ) ]
24- public static LoggerConfiguration Async (
25- this LoggerSinkConfiguration loggerSinkConfiguration ,
26- Action < LoggerSinkConfiguration > configure ,
27- int bufferSize )
28- {
29- return loggerSinkConfiguration . Async ( configure , bufferSize , false ) ;
30- }
31-
32- /// <summary>
33- /// Configure a sink to be invoked asynchronously, on a background worker thread.
34- /// </summary>
35- /// <param name="loggerSinkConfiguration">The <see cref="LoggerSinkConfiguration"/> being configured.</param>
36- /// <param name="configure">An action that configures the wrapped sink.</param>
37- /// <param name="bufferSize">The size of the concurrent queue used to feed the background worker thread. If
38- /// the thread is unable to process events quickly enough and the queue is filled, depending on
39- /// <paramref name="blockWhenFull"/> the queue will block or subsequent events will be dropped until
40- /// room is made in the queue.</param>
41- /// <param name="blockWhenFull">Block when the queue is full, instead of dropping events.</param>
42- /// <returns>A <see cref="LoggerConfiguration"/> allowing configuration to continue.</returns>
43- public static LoggerConfiguration Async (
44- this LoggerSinkConfiguration loggerSinkConfiguration ,
45- Action < LoggerSinkConfiguration > configure ,
46- int bufferSize = 10000 ,
47- bool blockWhenFull = false )
48- {
49- return loggerSinkConfiguration . Async ( configure , null , bufferSize , blockWhenFull ) ;
50- }
51-
52- /// <summary>
53- /// Configure a sink to be invoked asynchronously, on a background worker thread.
54- /// Accepts a reference to a <paramref name="monitor"/> that will be supplied the internal state interface for health monitoring purposes.
55- /// </summary>
56- /// <param name="loggerSinkConfiguration">The <see cref="LoggerSinkConfiguration"/> being configured.</param>
57- /// <param name="configure">An action that configures the wrapped sink.</param>
58- /// <param name="bufferSize">The size of the concurrent queue used to feed the background worker thread. If
59- /// the thread is unable to process events quickly enough and the queue is filled, depending on
60- /// <paramref name="blockWhenFull"/> the queue will block or subsequent events will be dropped until
61- /// room is made in the queue.</param>
62- /// <param name="blockWhenFull">Block when the queue is full, instead of dropping events.</param>
63- /// <param name="monitor">Monitor to supply buffer information to.</param>
64- /// <returns>A <see cref="LoggerConfiguration"/> allowing configuration to continue.</returns>
65- public static LoggerConfiguration Async (
66- this LoggerSinkConfiguration loggerSinkConfiguration ,
67- Action < LoggerSinkConfiguration > configure ,
68- IAsyncLogEventSinkMonitor monitor ,
69- int bufferSize = 10000 ,
70- bool blockWhenFull = false )
71- {
72- return LoggerSinkConfiguration . Wrap (
73- loggerSinkConfiguration ,
74- wrappedSink => new BackgroundWorkerSink ( wrappedSink , bufferSize , blockWhenFull , monitor ) ,
75- configure ,
76- LevelAlias . Minimum ,
77- null ) ;
78- }
46+ var wrapper = LoggerSinkConfiguration . Wrap (
47+ wrappedSink => new BackgroundWorkerSink ( wrappedSink , bufferSize , blockWhenFull , monitor ) ,
48+ configure ) ;
49+ return loggerSinkConfiguration . Sink ( wrapper ) ;
7950 }
8051}
0 commit comments