add using XLoggingService ...
This commit is contained in:
+1003
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
+29
-20
@@ -1,5 +1,5 @@
|
||||
|
||||
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\xAiMcpServer\Program.cs
|
||||
### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\xAiMcpServer\Program.cs
|
||||
|
||||
using System.Text;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
@@ -33,7 +33,7 @@ namespace xAiMcpServer
|
||||
}
|
||||
}
|
||||
|
||||
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\xAiMcpServer\Startup.cs
|
||||
### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\xAiMcpServer\Startup.cs
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
@@ -41,6 +41,7 @@ using System.Net.Http;
|
||||
using xAiMcpServer.DI;
|
||||
using Newtonsoft.Json;
|
||||
using System.Reflection;
|
||||
using xLoggingService.DI;
|
||||
using xIdentityService.DI;
|
||||
using xCommons.Extensions;
|
||||
using xAiService.Extensions;
|
||||
@@ -79,6 +80,10 @@ namespace xAiMcpServer
|
||||
services.AddXAppConfiguration(Configuration);
|
||||
var appConfiguration = services.GetRegisteredService<XAppConfiguration>();
|
||||
|
||||
//
|
||||
// Register Logging Service ...
|
||||
services.AddXLoggingService(Configuration);
|
||||
|
||||
//
|
||||
// Register Allowed Origins ...
|
||||
services.AddXCors(appConfiguration.AllowedOrigins);
|
||||
@@ -149,6 +154,10 @@ namespace xAiMcpServer
|
||||
app.UseHsts();
|
||||
}
|
||||
|
||||
//
|
||||
// Setting Environment in App Confiuration ...
|
||||
app.AddEnvironmentToXAppConfiguration(env.EnvironmentName);
|
||||
|
||||
//
|
||||
// Force Https Redirection ...
|
||||
app.UseHttpsRedirection();
|
||||
@@ -185,7 +194,7 @@ namespace xAiMcpServer
|
||||
}
|
||||
}
|
||||
|
||||
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\xAiMcpServer\Configurations\XAiMcpLinkExtractionToolConfiguration.cs
|
||||
### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\xAiMcpServer\Configurations\XAiMcpLinkExtractionToolConfiguration.cs
|
||||
|
||||
namespace xAiMcpServer.Configurations
|
||||
{
|
||||
@@ -196,7 +205,7 @@ namespace xAiMcpServer.Configurations
|
||||
}
|
||||
}
|
||||
|
||||
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\xAiMcpServer\Configurations\XAiMcpWebSearchToolConfiguration.cs
|
||||
### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\xAiMcpServer\Configurations\XAiMcpWebSearchToolConfiguration.cs
|
||||
|
||||
namespace xAiMcpServer.Configurations
|
||||
{
|
||||
@@ -247,7 +256,7 @@ namespace xAiMcpServer.Configurations
|
||||
}
|
||||
}
|
||||
|
||||
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\xAiMcpServer\Constants\ConfigurationNodeNames.cs
|
||||
### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\xAiMcpServer\Constants\ConfigurationNodeNames.cs
|
||||
|
||||
namespace xAiMcpServer.Constants
|
||||
{
|
||||
@@ -258,7 +267,7 @@ namespace xAiMcpServer.Constants
|
||||
}
|
||||
}
|
||||
|
||||
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\xAiMcpServer\Controllers\McpController.cs
|
||||
### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\xAiMcpServer\Controllers\McpController.cs
|
||||
|
||||
using xIdentityHelper;
|
||||
using System.Threading;
|
||||
@@ -336,7 +345,7 @@ namespace xAiMcpServer.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\xAiMcpServer\Controllers\StartupController.cs
|
||||
### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\xAiMcpServer\Controllers\StartupController.cs
|
||||
|
||||
using xCommons.Providers;
|
||||
using xCommons.Controllers;
|
||||
@@ -384,7 +393,7 @@ namespace xAiApi.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\xAiMcpServer\Controllers\TestIdentity.cs
|
||||
### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\xAiMcpServer\Controllers\TestIdentity.cs
|
||||
|
||||
using xCommons.Providers;
|
||||
using xCommons.Configurations;
|
||||
@@ -412,7 +421,7 @@ namespace xAiMcpServer.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\xAiMcpServer\DI\DiExtensions.cs
|
||||
### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\xAiMcpServer\DI\DiExtensions.cs
|
||||
|
||||
using System.Linq;
|
||||
using xIdentityHelper;
|
||||
@@ -718,7 +727,7 @@ namespace xAiMcpServer.DI
|
||||
}
|
||||
}
|
||||
|
||||
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\xAiMcpServer\Interfaces\IXAiMcpWebSearchService.cs
|
||||
### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\xAiMcpServer\Interfaces\IXAiMcpWebSearchService.cs
|
||||
|
||||
using System.Threading;
|
||||
using xAiMcpServer.Models;
|
||||
@@ -746,7 +755,7 @@ namespace xAiMcpServer.Interfaces
|
||||
}
|
||||
}
|
||||
|
||||
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\xAiMcpServer\Models\XExtractedLink.cs
|
||||
### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\xAiMcpServer\Models\XExtractedLink.cs
|
||||
|
||||
namespace xAiMcpServer.Models
|
||||
{
|
||||
@@ -758,7 +767,7 @@ namespace xAiMcpServer.Models
|
||||
}
|
||||
}
|
||||
|
||||
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\xAiMcpServer\Models\XLinkBundle.cs
|
||||
### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\xAiMcpServer\Models\XLinkBundle.cs
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
@@ -771,7 +780,7 @@ namespace xAiMcpServer.Models
|
||||
}
|
||||
}
|
||||
|
||||
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\xAiMcpServer\Models\XLinkContentResult.cs
|
||||
### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\xAiMcpServer\Models\XLinkContentResult.cs
|
||||
|
||||
namespace xAiMcpServer.Models
|
||||
{
|
||||
@@ -787,7 +796,7 @@ namespace xAiMcpServer.Models
|
||||
}
|
||||
}
|
||||
|
||||
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\xAiMcpServer\Models\XWebSearchToolResult.cs
|
||||
### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\xAiMcpServer\Models\XWebSearchToolResult.cs
|
||||
|
||||
namespace xAiMcpServer.Models
|
||||
{
|
||||
@@ -800,7 +809,7 @@ namespace xAiMcpServer.Models
|
||||
}
|
||||
}
|
||||
|
||||
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\xAiMcpServer\Providers\XAiMcpWebSearchService.cs
|
||||
### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\xAiMcpServer\Providers\XAiMcpWebSearchService.cs
|
||||
|
||||
using System;
|
||||
using System.Net;
|
||||
@@ -1103,7 +1112,7 @@ namespace xAiMcpServer.Providers
|
||||
}
|
||||
}
|
||||
|
||||
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\xAiMcpServer\Tools\XDateTools.cs
|
||||
### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\xAiMcpServer\Tools\XDateTools.cs
|
||||
|
||||
using System;
|
||||
using System.Text;
|
||||
@@ -1445,7 +1454,7 @@ namespace xAiMcpServer.Tools
|
||||
}
|
||||
}
|
||||
|
||||
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\xAiMcpServer\Tools\XEchoTools.cs
|
||||
### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\xAiMcpServer\Tools\XEchoTools.cs
|
||||
|
||||
|
||||
using xAiModels.Attributes;
|
||||
@@ -1468,7 +1477,7 @@ namespace xAiMcpServer.Tools
|
||||
}
|
||||
}
|
||||
|
||||
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\xAiMcpServer\Tools\XLinkExtractionTool.cs
|
||||
### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\xAiMcpServer\Tools\XLinkExtractionTool.cs
|
||||
|
||||
using System;
|
||||
using System.Net;
|
||||
@@ -1751,7 +1760,7 @@ namespace xAiMcpServer.Tools
|
||||
}
|
||||
}
|
||||
|
||||
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\xAiMcpServer\Tools\XUserTools.cs
|
||||
### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\xAiMcpServer\Tools\XUserTools.cs
|
||||
|
||||
using xIdentityHelper;
|
||||
using xModels.Extensions;
|
||||
@@ -1802,7 +1811,7 @@ namespace xAiMcpServer.Tools
|
||||
}
|
||||
}
|
||||
|
||||
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\xAiMcpServer\Tools\XWebSearchTool.cs
|
||||
### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\xAiMcpServer\Tools\XWebSearchTool.cs
|
||||
|
||||
using System;
|
||||
using System.Text;
|
||||
+198
-198
File diff suppressed because it is too large
Load Diff
+19
-19
@@ -1,5 +1,5 @@
|
||||
|
||||
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiService\Constants\ConfigurationNodeNames.cs
|
||||
### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xAiService\Constants\ConfigurationNodeNames.cs
|
||||
|
||||
namespace xAiService.Constants
|
||||
{
|
||||
@@ -9,7 +9,7 @@ namespace xAiService.Constants
|
||||
}
|
||||
}
|
||||
|
||||
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiService\Constants\XAiServiceConstants.cs
|
||||
### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xAiService\Constants\XAiServiceConstants.cs
|
||||
|
||||
namespace xAiService.Constants
|
||||
{
|
||||
@@ -28,7 +28,7 @@ namespace xAiService.Constants
|
||||
}
|
||||
}
|
||||
|
||||
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiService\Controllers\XAiMcpControllerBase.cs
|
||||
### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xAiService\Controllers\XAiMcpControllerBase.cs
|
||||
|
||||
using System.Threading;
|
||||
using xCommons.Providers;
|
||||
@@ -123,7 +123,7 @@ namespace xAiService.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiService\DI\XDIHelperExtension.cs
|
||||
### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xAiService\DI\XDIHelperExtension.cs
|
||||
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
@@ -167,7 +167,7 @@ namespace xAiService.DI
|
||||
}
|
||||
}
|
||||
|
||||
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiService\Extensions\DIExtensions.cs
|
||||
### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xAiService\Extensions\DIExtensions.cs
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
@@ -217,7 +217,7 @@ namespace xAiService.Extensions
|
||||
}
|
||||
}
|
||||
|
||||
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiService\Extensions\XAiServiceExtensions.cs
|
||||
### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xAiService\Extensions\XAiServiceExtensions.cs
|
||||
|
||||
using xAiModels.Models;
|
||||
using xCommons.Extensions;
|
||||
@@ -298,7 +298,7 @@ namespace xAiService.Extensions
|
||||
}
|
||||
}
|
||||
|
||||
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiService\Helpers\XAiMcpArgumentHelper.cs
|
||||
### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xAiService\Helpers\XAiMcpArgumentHelper.cs
|
||||
|
||||
using System;
|
||||
using Newtonsoft.Json.Linq;
|
||||
@@ -428,7 +428,7 @@ namespace xAiService.Helpers
|
||||
}
|
||||
}
|
||||
|
||||
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiService\Helpers\XAiMcpResultExtractionHelper.cs
|
||||
### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xAiService\Helpers\XAiMcpResultExtractionHelper.cs
|
||||
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
@@ -536,7 +536,7 @@ namespace xAiService.Helpers
|
||||
}
|
||||
}
|
||||
|
||||
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiService\Interfaces\IXAiMcpHandler.cs
|
||||
### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xAiService\Interfaces\IXAiMcpHandler.cs
|
||||
|
||||
using System.Threading;
|
||||
using Newtonsoft.Json.Linq;
|
||||
@@ -564,7 +564,7 @@ namespace xAiService.Interfaces
|
||||
}
|
||||
}
|
||||
|
||||
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiService\Interfaces\IXAiMcpUserContext.cs
|
||||
### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xAiService\Interfaces\IXAiMcpUserContext.cs
|
||||
|
||||
using xIdentityModels.Models;
|
||||
|
||||
@@ -610,7 +610,7 @@ namespace xAiService.Interfaces
|
||||
}
|
||||
}
|
||||
|
||||
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiService\Services\XAiMcpAIFunction.cs
|
||||
### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xAiService\Services\XAiMcpAIFunction.cs
|
||||
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
@@ -699,7 +699,7 @@ namespace xAiService.Services
|
||||
}
|
||||
}
|
||||
|
||||
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiService\Services\XAiMcpClient.cs
|
||||
### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xAiService\Services\XAiMcpClient.cs
|
||||
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
@@ -970,7 +970,7 @@ namespace xAiService.Services
|
||||
}
|
||||
}
|
||||
|
||||
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiService\Services\XAiMcpHandler.cs
|
||||
### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xAiService\Services\XAiMcpHandler.cs
|
||||
|
||||
using System;
|
||||
using System.Threading;
|
||||
@@ -1263,7 +1263,7 @@ namespace xAiService.Services
|
||||
}
|
||||
}
|
||||
|
||||
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiService\Services\XAiMcpHttpTransport.cs
|
||||
### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xAiService\Services\XAiMcpHttpTransport.cs
|
||||
|
||||
using System;
|
||||
using System.Text;
|
||||
@@ -1388,7 +1388,7 @@ namespace xAiService.Services
|
||||
}
|
||||
}
|
||||
|
||||
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiService\Services\XAiMcpSessionCleanupService.cs
|
||||
### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xAiService\Services\XAiMcpSessionCleanupService.cs
|
||||
|
||||
using System;
|
||||
using System.Threading;
|
||||
@@ -1433,7 +1433,7 @@ namespace xAiService.Services
|
||||
}
|
||||
}
|
||||
|
||||
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiService\Services\XAiMcpSessionStore.cs
|
||||
### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xAiService\Services\XAiMcpSessionStore.cs
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
@@ -1519,7 +1519,7 @@ namespace xAiService.Services
|
||||
}
|
||||
}
|
||||
|
||||
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiService\Services\XAiMcpToolBlueprint.cs
|
||||
### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xAiService\Services\XAiMcpToolBlueprint.cs
|
||||
|
||||
using System;
|
||||
using xAiModels.Models;
|
||||
@@ -1637,7 +1637,7 @@ namespace xAiService.Services
|
||||
}
|
||||
}
|
||||
|
||||
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiService\Services\XAiMcpToolScanner.cs
|
||||
### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xAiService\Services\XAiMcpToolScanner.cs
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
@@ -1877,7 +1877,7 @@ namespace xAiService.Services
|
||||
}
|
||||
}
|
||||
|
||||
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiService\Services\XAiMcpUserContext.cs
|
||||
### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xAiService\Services\XAiMcpUserContext.cs
|
||||
|
||||
using System.Threading;
|
||||
using xAiService.Interfaces;
|
||||
@@ -0,0 +1,906 @@
|
||||
|
||||
### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xLoggingService\Background\XLogDispatcher.cs
|
||||
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using xLoggingService.Models;
|
||||
using xLoggingService.Interfaces;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace xLoggingService.Background
|
||||
{
|
||||
public sealed class XLogDispatcher : IDisposable
|
||||
{
|
||||
private readonly Task worker;
|
||||
private readonly BlockingCollection<XLogEntry> queue;
|
||||
private readonly IReadOnlyCollection<IXLogWriter> writers;
|
||||
private readonly CancellationTokenSource cancellation = new CancellationTokenSource();
|
||||
|
||||
public XLogDispatcher(
|
||||
int capacity,
|
||||
IEnumerable<IXLogWriter> writers
|
||||
)
|
||||
{
|
||||
//
|
||||
queue = new BlockingCollection<XLogEntry>(Math.Max(100, capacity));
|
||||
this.writers = new List<IXLogWriter>(writers)
|
||||
.AsReadOnly();
|
||||
|
||||
//
|
||||
worker = Task.Run(RunAsync);
|
||||
}
|
||||
|
||||
public void Enqueue(XLogEntry entry)
|
||||
{
|
||||
if (!queue.IsAddingCompleted && !queue.TryAdd(entry)) { }
|
||||
}
|
||||
|
||||
private async Task RunAsync()
|
||||
{
|
||||
//
|
||||
try
|
||||
{
|
||||
//
|
||||
foreach (var entry in queue.GetConsumingEnumerable(cancellation.Token))
|
||||
{
|
||||
//
|
||||
foreach (var writer in writers)
|
||||
{
|
||||
//
|
||||
try
|
||||
{
|
||||
//
|
||||
await writer.WriteAsync(entry, cancellation.Token)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (OperationCanceledException) { }
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
//
|
||||
queue.CompleteAdding();
|
||||
|
||||
//
|
||||
try
|
||||
{
|
||||
worker.Wait(TimeSpan.FromSeconds(10));
|
||||
}
|
||||
catch { }
|
||||
|
||||
//
|
||||
cancellation.Cancel();
|
||||
queue.Dispose();
|
||||
cancellation.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xLoggingService\Configuration\XLoggingServiceConfiguration.cs
|
||||
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace xLoggingService.Configuration
|
||||
{
|
||||
public sealed class XLoggingServiceConfiguration
|
||||
{
|
||||
public bool Enabled { get; set; } = false;
|
||||
public XFileLogConfiguration File { get; set; } = new();
|
||||
public XLogQueueConfiguration Queue { get; set; } = new();
|
||||
public XEventLogConfiguration Event { get; set; } = new();
|
||||
public XDatabaseLogConfiguration Database { get; set; } = new();
|
||||
public LogLevel MinimumLevel { get; set; } = LogLevel.Information;
|
||||
}
|
||||
|
||||
public class XLogQueueConfiguration {
|
||||
public bool Enabled { get; set; }
|
||||
public int Capacity { get; set; } = 10000;
|
||||
public int ShutdownTimeoutSeconds { get; set; } = 10;
|
||||
}
|
||||
|
||||
public class XFileLogConfiguration {
|
||||
public bool Enabled { get; set; }
|
||||
public string Format { get; set; } = "Json";
|
||||
public string Directory { get; set; } = "./Logs";
|
||||
public int RetainedFileCountLimit { get; set; } = 30;
|
||||
public string FileName { get; set; } = "x-logging-.log";
|
||||
public LogLevel MinimumLevel { get; set; } = LogLevel.Information;
|
||||
}
|
||||
|
||||
public class XDatabaseLogConfiguration {
|
||||
public bool Enabled { get; set; } = false;
|
||||
public string ConnectionString { get; set; }
|
||||
public string TableName { get; set; } = "XLogs";
|
||||
public bool AutoCreateTable { get; set; } = true;
|
||||
public LogLevel MinimumLevel { get; set; } = LogLevel.Warning;
|
||||
public string Provider { get; set; } = "Microsoft.Data.Sqlite";
|
||||
}
|
||||
|
||||
public class XEventLogConfiguration {
|
||||
public bool Enabled { get; set; } = false;
|
||||
public string Sender { get; set; } = "Application";
|
||||
public string Action { get; set; } = "XLogCreated";
|
||||
public LogLevel MinimumLevel { get; set; } = LogLevel.Error;
|
||||
public string Topic { get; set; } = "x-logging-service-logs";
|
||||
}
|
||||
}
|
||||
|
||||
### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xLoggingService\Constants\ConfigurationNodeNames.cs
|
||||
|
||||
namespace xLoggingService.Constants
|
||||
{
|
||||
public partial struct ConfigurationNodeNames
|
||||
{
|
||||
public const string LOGGING_SERVICE_NODE = "LoggingServiceConfiguration";
|
||||
}
|
||||
}
|
||||
|
||||
### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xLoggingService\Constants\XLoggingServiceConstants.cs
|
||||
|
||||
namespace xLoggingService.Constants
|
||||
{
|
||||
public struct XLoggingServiceConstants
|
||||
{
|
||||
//
|
||||
// Service Extensions Log Tag ...
|
||||
public const string XLoggingServiceDILogTag = "XLoggingService";
|
||||
}
|
||||
}
|
||||
|
||||
### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xLoggingService\DI\XDIHelperExtension.cs
|
||||
|
||||
using System;
|
||||
using xCommons.Extensions;
|
||||
using xExceptions.Constants;
|
||||
using xLoggingService.Writers;
|
||||
using xEventService.Interfaces;
|
||||
using xLoggingService.Providers;
|
||||
using xLoggingService.Constants;
|
||||
using xLoggingService.Interfaces;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using xLoggingService.Configuration;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
|
||||
namespace xLoggingService.DI
|
||||
{
|
||||
public static class XDIHelperExtension
|
||||
{
|
||||
/// <summary>
|
||||
/// Retrieve Logging Service Configuration ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <returns></returns>
|
||||
public static XLoggingServiceConfiguration GetXLoggingServiceConfiguration(
|
||||
this IConfiguration source
|
||||
)
|
||||
{
|
||||
//
|
||||
var section = source
|
||||
.GetSection(ConfigurationNodeNames.LOGGING_SERVICE_NODE);
|
||||
|
||||
//
|
||||
var result = section.Get<XLoggingServiceConfiguration>();
|
||||
if (result.IsNull())
|
||||
{
|
||||
result = new();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Extract Service Configurations and Register it ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="configuration"></param>
|
||||
public static void AddXLoggingServiceConfiguration(
|
||||
this IServiceCollection source,
|
||||
IConfiguration configuration
|
||||
)
|
||||
{
|
||||
//
|
||||
var config = configuration.GetXLoggingServiceConfiguration();
|
||||
source.AddXLoggingServiceConfiguration(config);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Register Service Configuration ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="configuration"></param>
|
||||
public static void AddXLoggingServiceConfiguration(
|
||||
this IServiceCollection source,
|
||||
XLoggingServiceConfiguration configuration
|
||||
)
|
||||
{
|
||||
//
|
||||
if (configuration.IsNull())
|
||||
{
|
||||
//
|
||||
Log($"Invalid Configuration ...");
|
||||
XException.InvalidConfiguration.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
source.AddSingleton(configuration);
|
||||
Log($"Logging Configuration Registered Successfully ...");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Register Logging Service ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="configuration"></param>
|
||||
public static void AddXLoggingService(
|
||||
this IServiceCollection source,
|
||||
IConfiguration configuration
|
||||
)
|
||||
{
|
||||
//
|
||||
var config = configuration.GetXLoggingServiceConfiguration();
|
||||
source.AddLoggingService(
|
||||
configuration: config,
|
||||
lifeTime: ServiceLifetime.Scoped
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
#region Private
|
||||
/// <summary>
|
||||
/// a LogTag for Service ...
|
||||
/// </summary>
|
||||
private static string XLogTag = XLoggingServiceConstants.XLoggingServiceDILogTag;
|
||||
|
||||
/// <summary>
|
||||
/// print a log in Console ...
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
private static void Log(string message)
|
||||
{
|
||||
Console.WriteLine($"{XLogTag} => {message}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Register Logging Service ...
|
||||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
/// <param name="configuration"></param>
|
||||
/// <param name="lifeTime"></param>
|
||||
private static void AddLoggingService(
|
||||
this IServiceCollection services,
|
||||
XLoggingServiceConfiguration configuration,
|
||||
ServiceLifetime lifeTime = ServiceLifetime.Scoped
|
||||
)
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
if (lifeTime.IsNull())
|
||||
{
|
||||
//
|
||||
Log($"Invalid Service Lifetime ...");
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
// Register Service Configuration ...
|
||||
services.AddXLoggingServiceConfiguration(configuration);
|
||||
|
||||
//
|
||||
// File Log Provider ...
|
||||
if (configuration.File.Enabled)
|
||||
{
|
||||
//
|
||||
services.TryAddEnumerable(
|
||||
ServiceDescriptor.Singleton<IXLogWriter, XFileLogWriter>());
|
||||
|
||||
//
|
||||
Log("FileLogWriter registered.");
|
||||
}
|
||||
|
||||
//
|
||||
// Database Log Provider ...
|
||||
if (configuration.Database.Enabled)
|
||||
{
|
||||
//
|
||||
services.TryAddEnumerable(
|
||||
ServiceDescriptor.Singleton<IXLogWriter, XDatabaseLogWriter>());
|
||||
|
||||
//
|
||||
Log("DatabaseLogWriter registered.");
|
||||
}
|
||||
|
||||
//
|
||||
// Event Service Provider ...
|
||||
if (configuration.Event.Enabled)
|
||||
{
|
||||
//
|
||||
var eventService = services.GetRegisteredService<IXEventServiceProvider>();
|
||||
if (eventService.IsNull())
|
||||
{
|
||||
//
|
||||
Log("Event Service not Provided ...");
|
||||
XException.InvalidConfiguration.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
services.TryAddEnumerable(
|
||||
ServiceDescriptor.Singleton<IXLogWriter, XEventLogWriter>());
|
||||
|
||||
//
|
||||
Log("EventLogWriter registered.");
|
||||
}
|
||||
|
||||
//
|
||||
services.TryAddEnumerable(
|
||||
ServiceDescriptor.Singleton<ILoggerProvider, XLoggerProvider>());
|
||||
|
||||
//
|
||||
Log($"Logging Service registered successfully ...");
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xLoggingService\Extensions\XLoggingServiceExtensions.cs
|
||||
|
||||
using xCommons.Extensions;
|
||||
using xLoggingService.Models;
|
||||
using xCommons.Configurations;
|
||||
|
||||
namespace xLoggingService.Extensions
|
||||
{
|
||||
public static class XLoggingServiceExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Enrich LogEntry ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="configuration"></param>
|
||||
/// <returns></returns>
|
||||
public static XLogEntry Enrich(
|
||||
this XLogEntry source,
|
||||
XAppConfiguration configuration
|
||||
)
|
||||
{
|
||||
//
|
||||
if (source.IsNull() || configuration.IsNull())
|
||||
{
|
||||
return source;
|
||||
}
|
||||
|
||||
//
|
||||
source.Application = configuration.Name;
|
||||
|
||||
//
|
||||
return source;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xLoggingService\Interfaces\IXLogWriter.cs
|
||||
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using xLoggingService.Models;
|
||||
|
||||
namespace xLoggingService.Interfaces
|
||||
{
|
||||
public interface IXLogWriter
|
||||
{
|
||||
/// <summary>
|
||||
/// Write Log ...
|
||||
/// </summary>
|
||||
/// <param name="entry"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task WriteAsync(
|
||||
XLogEntry entry,
|
||||
CancellationToken cancellationToken
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xLoggingService\Models\XLogEntry.cs
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace xLoggingService.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// a Log which Issued ...
|
||||
/// </summary>
|
||||
public class XLogEntry
|
||||
{
|
||||
public int EventId { get; set; }
|
||||
public string State { get; set; }
|
||||
public string SpanId { get; set; }
|
||||
public LogLevel Level { get; set; }
|
||||
public string Message { get; set; }
|
||||
public string TraceId { get; set; }
|
||||
public string Category { get; set; }
|
||||
public string Exception { get; set; }
|
||||
public DateTime Timestamp { get; set; }
|
||||
public string Application { get; set; }
|
||||
public string Environment { get; set; }
|
||||
public string MachineName { get; set; }
|
||||
public string CorrelationId { get; set; }
|
||||
public IDictionary<string, string> Scope { get; set; } = new Dictionary<string, string>();
|
||||
}
|
||||
}
|
||||
|
||||
### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xLoggingService\Providers\XLoggerProvider.cs
|
||||
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
using System.Diagnostics;
|
||||
using xLoggingService.Models;
|
||||
using xCommons.Configurations;
|
||||
using System.Collections.Generic;
|
||||
using xLoggingService.Background;
|
||||
using xLoggingService.Interfaces;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using xLoggingService.Configuration;
|
||||
|
||||
namespace xLoggingService.Providers
|
||||
{
|
||||
public class XLoggerProvider : ILoggerProvider
|
||||
{
|
||||
//
|
||||
private readonly XLogDispatcher dispatcher;
|
||||
private readonly XAppConfiguration configuration;
|
||||
private readonly XLoggingServiceConfiguration config;
|
||||
private readonly IReadOnlyCollection<IXLogWriter> writers;
|
||||
|
||||
public XLoggerProvider(
|
||||
XAppConfiguration configuration,
|
||||
XLoggingServiceConfiguration config,
|
||||
IEnumerable<IXLogWriter> writers
|
||||
)
|
||||
{
|
||||
//
|
||||
this.config = config;
|
||||
this.configuration = configuration;
|
||||
this.writers = new List<IXLogWriter>(writers)
|
||||
.AsReadOnly();
|
||||
|
||||
//
|
||||
dispatcher = new XLogDispatcher(
|
||||
config.Queue.Capacity, this.writers);
|
||||
}
|
||||
|
||||
public ILogger CreateLogger(string categoryName)
|
||||
{
|
||||
//
|
||||
return new XLogger(
|
||||
config: config,
|
||||
category: categoryName,
|
||||
dispatcher: dispatcher,
|
||||
configuration: configuration
|
||||
);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
dispatcher.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public class XLogger : ILogger
|
||||
{
|
||||
//
|
||||
private readonly string category;
|
||||
private readonly XLogDispatcher dispatcher;
|
||||
private readonly XAppConfiguration configuration;
|
||||
private readonly XLoggingServiceConfiguration config;
|
||||
|
||||
public XLogger(
|
||||
string category,
|
||||
XLogDispatcher dispatcher,
|
||||
XAppConfiguration configuration,
|
||||
XLoggingServiceConfiguration config
|
||||
)
|
||||
{
|
||||
//
|
||||
this.config = config;
|
||||
this.category = category;
|
||||
this.dispatcher = dispatcher;
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
public IDisposable BeginScope<TState>(TState state)
|
||||
{
|
||||
return NullScope.Instance;
|
||||
}
|
||||
|
||||
public bool IsEnabled(LogLevel level)
|
||||
{
|
||||
//
|
||||
var result =
|
||||
config.Enabled &&
|
||||
level >= config.MinimumLevel &&
|
||||
level != LogLevel.None;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
public void Log<TState>(
|
||||
LogLevel level,
|
||||
EventId eventId,
|
||||
TState state,
|
||||
Exception exception,
|
||||
Func<TState, Exception, string> formatter
|
||||
)
|
||||
{
|
||||
//
|
||||
if (!IsEnabled(level))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
var activity = Activity.Current;
|
||||
dispatcher.Enqueue(new XLogEntry
|
||||
{
|
||||
Level = level,
|
||||
Category = category,
|
||||
EventId = eventId.Id,
|
||||
TraceId = activity?.Id,
|
||||
SpanId = activity?.RootId,
|
||||
Timestamp = DateTime.UtcNow,
|
||||
Message = formatter == null
|
||||
? state == null
|
||||
? string.Empty
|
||||
: state.ToString()
|
||||
: formatter(state, exception),
|
||||
Exception = exception == null
|
||||
? null
|
||||
: exception.ToString(),
|
||||
State = state == null
|
||||
? null :
|
||||
JsonConvert.SerializeObject(state),
|
||||
Application = configuration.Name,
|
||||
MachineName = Environment.MachineName,
|
||||
Environment = configuration.Environment,
|
||||
});
|
||||
}
|
||||
|
||||
private sealed class NullScope : IDisposable {
|
||||
public static readonly NullScope Instance = new();
|
||||
public void Dispose() { }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xLoggingService\Writers\XDatabaseLogWriter.cs
|
||||
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Data.Common;
|
||||
using xCommons.Extensions;
|
||||
using System.Threading.Tasks;
|
||||
using xLoggingService.Models;
|
||||
using xCommons.Configurations;
|
||||
using xLoggingService.Interfaces;
|
||||
using xLoggingService.Extensions;
|
||||
using xLoggingService.Configuration;
|
||||
|
||||
namespace xLoggingService.Writers
|
||||
{
|
||||
public sealed class XDatabaseLogWriter : IXLogWriter
|
||||
{
|
||||
//
|
||||
private bool initialized;
|
||||
private readonly object sync = new();
|
||||
private readonly XDatabaseLogConfiguration config;
|
||||
private readonly XAppConfiguration appConfiguration;
|
||||
|
||||
public XDatabaseLogWriter(
|
||||
XDatabaseLogConfiguration config,
|
||||
XAppConfiguration appConfiguration
|
||||
)
|
||||
{
|
||||
//
|
||||
this.config = config;
|
||||
this.appConfiguration = appConfiguration;
|
||||
}
|
||||
|
||||
public Task WriteAsync(
|
||||
XLogEntry e,
|
||||
CancellationToken token
|
||||
)
|
||||
{
|
||||
//
|
||||
if (e.IsNull())
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Task Enrichment ...
|
||||
e = e.Enrich(appConfiguration);
|
||||
|
||||
//
|
||||
if (e.Level < config.MinimumLevel || config.ConnectionString.IsNullOrEmpty())
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
//
|
||||
try
|
||||
{
|
||||
//
|
||||
lock (sync)
|
||||
{
|
||||
//
|
||||
using (var c = CreateConnection())
|
||||
{
|
||||
//
|
||||
c.Open();
|
||||
if (!initialized)
|
||||
{
|
||||
using (var cmd = c.CreateCommand())
|
||||
{
|
||||
//
|
||||
cmd.CommandText = $"CREATE TABLE IF NOT EXISTS [{config.TableName}] (Id INTEGER PRIMARY KEY, Timestamp TEXT, Level TEXT, Category TEXT, EventId INTEGER, Message TEXT, Exception TEXT, State TEXT, Application TEXT, Environment TEXT, MachineName TEXT, TraceId TEXT, SpanId TEXT, CorrelationId TEXT)";
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
//
|
||||
using (var cmd = c.CreateCommand())
|
||||
{
|
||||
//
|
||||
cmd.CommandText = $"INSERT INTO [{config.TableName}] (Timestamp,Level,Category,EventId,Message,Exception,State,Application,Environment,MachineName,TraceId,SpanId,CorrelationId) VALUES (@Timestamp,@Level,@Category,@EventId,@Message,@Exception,@State,@Application,@Environment,@MachineName,@TraceId,@SpanId,@CorrelationId)";
|
||||
|
||||
//
|
||||
Add(cmd, "@State", e.State);
|
||||
Add(cmd, "@SpanId", e.SpanId);
|
||||
Add(cmd, "@EventId", e.EventId);
|
||||
Add(cmd, "@Message", e.Message);
|
||||
Add(cmd, "@TraceId", e.TraceId);
|
||||
Add(cmd, "@Category", e.Category);
|
||||
Add(cmd, "@Exception", e.Exception);
|
||||
Add(cmd, "@Level", e.Level.ToString());
|
||||
Add(cmd, "@Application", e.Application);
|
||||
Add(cmd, "@Environment", e.Environment);
|
||||
Add(cmd, "@MachineName", e.MachineName);
|
||||
Add(cmd, "@CorrelationId", e.CorrelationId);
|
||||
Add(cmd, "@Timestamp", e.Timestamp.ToString("O"));
|
||||
|
||||
//
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
|
||||
//
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private DbConnection CreateConnection()
|
||||
{
|
||||
//
|
||||
var typeName =
|
||||
config.Provider == "Microsoft.Data.Sqlite"
|
||||
? "Microsoft.Data.Sqlite.SqliteConnection, Microsoft.Data.Sqlite"
|
||||
: config.Provider == "System.Data.SqlClient" ?
|
||||
"System.Data.SqlClient.SqlConnection, System.Data.SqlClient"
|
||||
: config.Provider;
|
||||
|
||||
//
|
||||
var type = Type.GetType(typeName, false);
|
||||
if (type.IsNull())
|
||||
{
|
||||
throw new InvalidOperationException("Database provider was not found: " + typeName);
|
||||
}
|
||||
|
||||
//
|
||||
var c = (DbConnection)Activator.CreateInstance(type);
|
||||
c.ConnectionString = config.ConnectionString;
|
||||
|
||||
//
|
||||
return c;
|
||||
}
|
||||
|
||||
private static void Add(
|
||||
DbCommand c,
|
||||
string name,
|
||||
object value
|
||||
) {
|
||||
//
|
||||
var p = c.CreateParameter();
|
||||
p.ParameterName = name;
|
||||
p.Value = (object)value ?? DBNull.Value;
|
||||
c.Parameters.Add(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xLoggingService\Writers\XEventLogWriter.cs
|
||||
|
||||
using System;
|
||||
using System.Threading;
|
||||
using xCommons.Extensions;
|
||||
using xEventService.Models;
|
||||
using System.Threading.Tasks;
|
||||
using xLoggingService.Models;
|
||||
using xCommons.Configurations;
|
||||
using xEventService.Interfaces;
|
||||
using System.Collections.Generic;
|
||||
using xLoggingService.Interfaces;
|
||||
using xLoggingService.Extensions;
|
||||
using xLoggingService.Configuration;
|
||||
|
||||
namespace xLoggingService.Writers
|
||||
{
|
||||
public sealed class XEventLogWriter : IXLogWriter
|
||||
{
|
||||
|
||||
//
|
||||
private readonly XAppConfiguration appConfiguration;
|
||||
private readonly XLoggingServiceConfiguration config;
|
||||
private readonly Func<IXEventServiceProvider> resolver;
|
||||
|
||||
public XEventLogWriter(
|
||||
XAppConfiguration appConfiguration,
|
||||
XLoggingServiceConfiguration config,
|
||||
Func<IXEventServiceProvider> resolver
|
||||
)
|
||||
{
|
||||
//
|
||||
this.config = config;
|
||||
this.resolver = resolver;
|
||||
this.appConfiguration = appConfiguration;
|
||||
}
|
||||
|
||||
public async Task WriteAsync(
|
||||
XLogEntry entry,
|
||||
CancellationToken token
|
||||
)
|
||||
{
|
||||
//
|
||||
if (entry.IsNull())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Task Enrichment ...
|
||||
entry = entry.Enrich(appConfiguration);
|
||||
|
||||
//
|
||||
var provider = resolver();
|
||||
if (provider.IsNull() || entry.Level < config.Event.MinimumLevel)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
var payload = new Dictionary<string, string> {
|
||||
{ nameof(XLogEntry.Category), entry.Category },
|
||||
{ nameof(XLogEntry.Level), entry.Level.ToString() },
|
||||
{ nameof(XLogEntry.State), entry.State ?? string.Empty },
|
||||
{ nameof(XLogEntry.TraceId), entry.TraceId ?? string.Empty } ,
|
||||
{ nameof(XLogEntry.Exception), entry.Exception ?? string.Empty },
|
||||
};
|
||||
|
||||
//
|
||||
await provider.SendMessageAsync(
|
||||
new XEventMessage
|
||||
{
|
||||
Payload = payload,
|
||||
Message = entry.Message,
|
||||
Offset = entry.Timestamp,
|
||||
Sender = config.Event.Sender,
|
||||
Action = config.Event.Action,
|
||||
},
|
||||
config.Event.Topic,
|
||||
token
|
||||
).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
### FILE: C:\Users\SaherElm\Documents\Projects\xSaherelmWorkspace\Modules\xLoggingService\Writers\XFileLogWriter.cs
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
using System.Threading;
|
||||
using xCommons.Extensions;
|
||||
using xExceptions.Constants;
|
||||
using System.Threading.Tasks;
|
||||
using xLoggingService.Models;
|
||||
using xCommons.Configurations;
|
||||
using xLoggingService.Interfaces;
|
||||
using xLoggingService.Extensions;
|
||||
using xLoggingService.Configuration;
|
||||
|
||||
namespace xLoggingService.Writers
|
||||
{
|
||||
public sealed class XFileLogWriter : IXLogWriter
|
||||
{
|
||||
//
|
||||
private readonly object sync = new();
|
||||
private readonly XAppConfiguration appConfiguration;
|
||||
private readonly XLoggingServiceConfiguration configuration;
|
||||
|
||||
public XFileLogWriter(
|
||||
XAppConfiguration appConfiguration,
|
||||
XLoggingServiceConfiguration configuration
|
||||
)
|
||||
{
|
||||
//
|
||||
if (configuration.IsNull() || appConfiguration.IsNull())
|
||||
{
|
||||
XException.InvalidConfiguration.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
this.configuration = configuration;
|
||||
this.appConfiguration = appConfiguration;
|
||||
|
||||
//
|
||||
Directory.CreateDirectory(configuration.File.Directory);
|
||||
}
|
||||
|
||||
public Task WriteAsync(
|
||||
XLogEntry entry,
|
||||
CancellationToken token
|
||||
)
|
||||
{
|
||||
//
|
||||
if (entry.IsNull())
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Task Enrichment ...
|
||||
entry = entry.Enrich(appConfiguration);
|
||||
|
||||
//
|
||||
if (entry.Level < configuration.File.MinimumLevel)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
//
|
||||
var path = Path.Combine(configuration.File.Directory, configuration.File.FileName.Replace("-", "-"));
|
||||
|
||||
//
|
||||
lock (sync)
|
||||
{
|
||||
//
|
||||
File.AppendAllText(path, configuration.File.Format.Equals(
|
||||
"Json",
|
||||
StringComparison.OrdinalIgnoreCase)
|
||||
? JsonConvert.SerializeObject(entry) + Environment.NewLine
|
||||
: $"{entry.Timestamp:O} [{entry.Level}] {entry.Category}: {entry.Message}{Environment.NewLine}", Encoding.UTF8);
|
||||
}
|
||||
|
||||
//
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
Submodule Modules/xLoggingService updated: 777ceaa8f0...0fe37483bc
+1
-1
Submodule xAiApi updated: b58f1dd736...c24c14eb74
+1
-1
Submodule xAiMcpServer updated: 63b922f09b...0bc45bd8b9
+1
-1
Submodule xApi updated: c711cae78f...18eb5d92e1
+1
-1
Submodule xIds updated: df3ed7868b...b311b1e391
Reference in New Issue
Block a user