2using System.Diagnostics;
3using System.Globalization;
5using Microsoft.Extensions.Configuration;
6using Microsoft.Extensions.DependencyInjection;
7using Microsoft.Extensions.DependencyInjection.Extensions;
8using Microsoft.Extensions.Logging;
11using Serilog.Configuration;
12using Serilog.Sinks.Elasticsearch;
91 public static IServiceCollection
AddFileDownloader(
this IServiceCollection serviceCollection)
93 ArgumentNullException.ThrowIfNull(serviceCollection);
97 return serviceCollection;
105 public static IServiceCollection
AddGitHub(
this IServiceCollection serviceCollection)
107 ArgumentNullException.ThrowIfNull(serviceCollection);
112 return serviceCollection;
120 where TLoggerProvider : class, ILoggerProvider
123 throw new InvalidOperationException(
"Cannot have multiple additionalLoggerProviders!");
134 ArgumentNullException.ThrowIfNull(serviceCollection);
147 where TConfig :
class
149 ArgumentNullException.ThrowIfNull(serviceCollection);
150 ArgumentNullException.ThrowIfNull(configuration);
154 var configType = typeof(TConfig);
155 var sectionField = configType.GetField(SectionFieldName) ??
throw new InvalidOperationException(
156 String.Format(CultureInfo.InvariantCulture,
"{0} has no {1} field!", configType, SectionFieldName));
157 var stringType = typeof(
string);
158 if (sectionField.FieldType != stringType)
159 throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture,
"{0} has invalid {1} field type, must be {2}!", configType, SectionFieldName, stringType));
161 var sectionName = (string)sectionField.GetValue(
null)!;
163 return serviceCollection.Configure<TConfig>(configuration.GetSection(sectionName));
177 this IServiceCollection serviceCollection,
178 Action<LoggerConfiguration> configurationAction,
179 Action<LoggerSinkConfiguration>? sinkConfigurationAction =
null,
180 ElasticsearchSinkOptions? elasticsearchSinkOptions =
null,
184 if (internalConfiguration !=
null)
185 ArgumentNullException.ThrowIfNull(fileLoggingConfiguration);
187 return serviceCollection.AddLogging(builder =>
189 builder.ClearProviders();
191 var configuration =
new LoggerConfiguration()
195 configurationAction?.Invoke(configuration);
198 .Enrich.FromLogContext()
200 .Async(sinkConfiguration =>
202 var
template =
"[{Timestamp:HH:mm:ss}] {Level:w3}: {SourceContext:l} ("
203 + SerilogContextHelper.Template
204 +
"){NewLine} {Message:lj}{NewLine}{Exception}";
206 if (!((internalConfiguration?.UsingSystemD ??
false) && !(fileLoggingConfiguration?.Disable ??
false)))
207 sinkConfiguration.Console(outputTemplate:
template, formatProvider: CultureInfo.InvariantCulture);
208 sinkConfigurationAction?.Invoke(sinkConfiguration);
211 if (elasticsearchSinkOptions !=
null)
212 configuration.WriteTo.Elasticsearch(elasticsearchSinkOptions);
214 builder.AddSerilog(configuration.CreateLogger(),
true);
216 if (Debugger.IsAttached)
232 where THubMethods :
class
234 ArgumentNullException.ThrowIfNull(services);
246 UseChatProviderFactory<ProviderFactory>();
247 UseGitHubServiceFactory<GitHubServiceFactory>();
248 UseFileDownloader<FileDownloader>();
File logging configuration options.
General configuration options.
const string Section
The key for the Microsoft.Extensions.Configuration.IConfigurationSection the GeneralConfiguration res...
Unstable configuration options used internally by TGS.
Extensions for IServiceCollection.
static void UseAdditionalLoggerProvider< TLoggerProvider >()
Add an additional ILoggerProvider to IServiceCollections that call SetupLogging(IServiceCollection,...
static void AddHub< THub, THubMethods >(this IServiceCollection services)
Attempt to add the given THub to services.
static void UseDefaultServices()
Set the modifiable services to their default types.
static IServiceCollection UseStandardConfig< TConfig >(this IServiceCollection serviceCollection, IConfiguration configuration)
Add a standard TConfig binding.
static ? Type fileDownloaderType
The IFileDownloader implementation used in calls to AddFileDownloader(IServiceCollection).
static void UseChatProviderFactory< TProviderFactory >()
Change the Type used as an implementation for calls to AddChatProviderFactory(IServiceCollection).
static ? Type gitHubServiceFactoryType
The IGitHubServiceFactory implementation used in calls to AddGitHub(IServiceCollection).
static IServiceCollection AddFileDownloader(this IServiceCollection serviceCollection)
Adds a IFileDownloader implementation to the given serviceCollection .
static IServiceCollection AddChatProviderFactory(this IServiceCollection serviceCollection)
Adds a IProviderFactory implementation to the given serviceCollection .
static ServiceCollectionExtensions()
Initializes static members of the ServiceCollectionExtensions class.
static IServiceCollection AddGitHub(this IServiceCollection serviceCollection)
Adds a IGitHubServiceFactory implementation to the given serviceCollection .
static IServiceCollection SetupLogging(this IServiceCollection serviceCollection, Action< LoggerConfiguration > configurationAction, Action< LoggerSinkConfiguration >? sinkConfigurationAction=null, ElasticsearchSinkOptions? elasticsearchSinkOptions=null, InternalConfiguration? internalConfiguration=null, FileLoggingConfiguration? fileLoggingConfiguration=null)
Clear previous providers and configure logging.
static ? Type chatProviderFactoryType
The IProviderFactory implementation used in calls to AddChatProviderFactory(IServiceCollection).
static ? ServiceDescriptor additionalLoggerProvider
A ServiceDescriptor for an additional ILoggerProvider to use.
static void UseFileDownloader< TFileDownloader >()
Change the Type used as an implementation for calls to AddGitHub(IServiceCollection).
static void UseGitHubServiceFactory< TGitHubServiceFactory >()
Change the Type used as an implementation for calls to AddGitHub(IServiceCollection).
An implementation of IHubContext<THub> with User connection ID mapping.
Base class for Hub<T>s that want to map their connection IDs to Models.PermissionSets.
For creating IGitHubClients.
Factory for IGitHubServices.
A IHubContext<THub> that maps Users to their connection IDs.
Handles mapping connection IDs to Users for a given THub .