Added Serilog to manage logs

Handle required fields while starting
This commit is contained in:
Tech Garage 2024-07-21 00:31:22 +03:30
parent 6fbfaa1007
commit b128154c60
17 changed files with 749 additions and 154 deletions

View file

@ -0,0 +1,47 @@
using Microsoft.Extensions.DependencyInjection;
using Serilog.Ui.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Serilog.Ui.SqliteDataProvider
{
/// <summary>
/// Sqlite data provider specific extension methods for <see cref="SerilogUiOptionsBuilder"/>.
/// </summary>
public static class SerilogUiOptionBuilderExtensions
{
/// <summary>
/// Configures the SerilogUi to connect to a Sqlite database.
/// </summary>
/// <param name="optionsBuilder"> The options builder. </param>
/// <param name="connectionString"> The connection string. </param>
/// <param name="tableName"> Name of the table. </param>
/// <exception cref="ArgumentNullException"> throw if connectionString is null </exception>
/// <exception cref="ArgumentNullException"> throw is tableName is null </exception>
public static void UseSqliteServer(
this SerilogUiOptionsBuilder optionsBuilder,
string connectionString,
string tableName
)
{
if (string.IsNullOrWhiteSpace(connectionString))
throw new ArgumentNullException(nameof(connectionString));
if (string.IsNullOrWhiteSpace(tableName))
throw new ArgumentNullException(nameof(tableName));
var relationProvider = new RelationalDbOptions
{
ConnectionString = connectionString,
TableName = tableName
};
((ISerilogUiOptionsBuilder)optionsBuilder).Services
.AddScoped<IDataProvider, SqliteDataProvider>(p => ActivatorUtilities.CreateInstance<SqliteDataProvider>(p, relationProvider));
}
}
}