|
23 | 23 |
|
24 | 24 | namespace Serilog.Context |
25 | 25 | { |
| 26 | + /// <summary> |
| 27 | + /// Holds global properties that can be attached to log events. To |
| 28 | + /// configure, use the <see cref="LoggerEnrichmentConfigurationExtensions.FromGlobalLogContext(Configuration.LoggerEnrichmentConfiguration)" /> method. |
| 29 | + /// </summary> |
| 30 | + /// <example> |
| 31 | + /// Configuration: |
| 32 | + /// <code lang="C#"> |
| 33 | + /// Log.Logger = new LoggerConfiguration() |
| 34 | + /// .Enrich.FromGlobalLogContext() |
| 35 | + /// // ... other configuration ... |
| 36 | + /// .CreateLogger(); |
| 37 | + /// </code> |
| 38 | + /// Usage: |
| 39 | + /// <code lang="C#"> |
| 40 | + /// GlobalLogContext.PushProperty("AppVersion", buildInfo.Version); |
| 41 | + /// |
| 42 | + /// Log.Information("The AppVersion property will be attached to this event and all others following"); |
| 43 | + /// Log.Warning("The AppVersion property will also be attached to this event and all others following"); |
| 44 | + /// </code> |
| 45 | + /// </example> |
| 46 | + /// <remarks> |
| 47 | + /// The scope of the context is global to the application and is |
| 48 | + /// shared between all threads. |
| 49 | + /// </remarks> |
26 | 50 | public static class GlobalLogContext |
27 | 51 | { |
28 | 52 | private static readonly SemaphoreSlim _semaphoreSlim = new SemaphoreSlim(1, 1); |
29 | 53 | private static ImmutableStack<ILogEventEnricher> _data; |
30 | 54 |
|
| 55 | + /// <summary> |
| 56 | + /// Acquires an exclusive lock on the global log context. |
| 57 | + /// </summary> |
| 58 | + /// <returns> |
| 59 | + /// A token that can be disposed, in order to release |
| 60 | + /// the exclusive lock on the global log context. |
| 61 | + /// </returns> |
31 | 62 | public static IDisposable Lock() |
32 | 63 | { |
33 | 64 | _semaphoreSlim.Wait(); |
34 | 65 | return new ContextLock(); |
35 | 66 | } |
36 | 67 |
|
| 68 | + /// <summary> |
| 69 | + /// Acquires an exclusive lock on the global log context, asynchronously. |
| 70 | + /// </summary> |
| 71 | + /// <returns> |
| 72 | + /// A token that can be disposed, in order to release |
| 73 | + /// the exclusive lock on the global log context. |
| 74 | + /// </returns> |
37 | 75 | public static async Task<IDisposable> LockAsync() |
38 | 76 | { |
39 | 77 | await _semaphoreSlim.WaitAsync().ConfigureAwait(false); |
|
0 commit comments