diff --git a/lab_0/Program.cs b/lab_0/Program.cs
index bce618e..e9c7ce4 100644
--- a/lab_0/Program.cs
+++ b/lab_0/Program.cs
@@ -1,39 +1,48 @@
using Microsoft.Extensions.DependencyInjection;
-using NLog.Extensions.Logging;
-using Microsoft.Extensions.Configuration;
using ProjectBus;
-using System;
using Microsoft.Extensions.Logging;
+using Serilog;
+using Microsoft.Extensions.Configuration;
-namespace lab_0
+
+namespace ProjectBus;
+
+internal static class Program
{
- internal static class Program
+ ///
+ /// The main entry point for the application.
+ ///
+ [STAThread]
+ static void Main()
{
- ///
- /// The main entry point for the application.
- ///
- [STAThread]
- static void Main()
+ // To customize application configuration such as set high DPI settings or default font,
+ // see https://aka.ms/applicationconfiguration.
+ ApplicationConfiguration.Initialize();
+ var services = new ServiceCollection();
+ ConfigureServices(services);
+ using (ServiceProvider serviceProvider = services.BuildServiceProvider())
{
- // To customize application configuration such as set high DPI settings or default font,
- // see https://aka.ms/applicationconfiguration.
- ApplicationConfiguration.Initialize();
- var services = new ServiceCollection();
- ConfigureServices(services);
- using (ServiceProvider serviceProvider = services.BuildServiceProvider())
- {
- Application.Run(serviceProvider.GetRequiredService());
- }
- }
-
- private static void ConfigureServices(ServiceCollection services)
- {
- services.AddSingleton()
- .AddLogging(option =>
- {
- option.SetMinimumLevel(LogLevel.Information);
- option.AddNLog("nlog.config");
- });
+ Application.Run(serviceProvider.GetRequiredService());
}
}
+
+ private static void ConfigureServices(ServiceCollection services)
+ {
+ services.AddSingleton().AddLogging(option =>
+ {
+ string[] path = Directory.GetCurrentDirectory().Split('\\');
+ string pathNeed = "";
+ for (int i = 0; i < path.Length - 3; i++)
+ {
+ pathNeed += path[i] + "\\";
+ }
+
+ var configuration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory())
+ .AddJsonFile(path: $"{pathNeed}serilogConfig.json", optional: false, reloadOnChange: true)
+ .Build();
+ var logger = new LoggerConfiguration().ReadFrom.Configuration(configuration).CreateLogger();
+ option.SetMinimumLevel(LogLevel.Information);
+ option.AddSerilog(logger);
+ });
+ }
}
\ No newline at end of file
diff --git a/lab_0/ProjectBus.csproj b/lab_0/ProjectBus.csproj
index d258f05..7697e5a 100644
--- a/lab_0/ProjectBus.csproj
+++ b/lab_0/ProjectBus.csproj
@@ -9,8 +9,12 @@
-
-
+
+
+
+
+
+
@@ -28,10 +32,4 @@
-
-
- Always
-
-
-
\ No newline at end of file
diff --git a/lab_0/nlog.config b/lab_0/nlog.config
deleted file mode 100644
index 98fa0dd..0000000
--- a/lab_0/nlog.config
+++ /dev/null
@@ -1,15 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/lab_0/serilogConfig.json b/lab_0/serilogConfig.json
new file mode 100644
index 0000000..bff9cbf
--- /dev/null
+++ b/lab_0/serilogConfig.json
@@ -0,0 +1,20 @@
+{
+ "Serilog": {
+ "Using": [ "Serilog.Sinks.File" ],
+ "MinimumLevel": "Information",
+ "WriteTo": [
+ {
+ "Name": "File",
+ "Args": {
+ "path": "Logs/log_.log",
+ "rollingInterval": "Day",
+ "outputTemplate": "[{Timestamp:HH:mm:ss.fff}]{Level:u4}: {Message:lj}{NewLine}{Exception}"
+ }
+ }
+ ],
+ "Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ],
+ "Properties": {
+ "Application": "Bus"
+ }
+ }
+}
\ No newline at end of file