From a8ae769f5c48a5bcf00f54205364d49fe3181c9c Mon Sep 17 00:00:00 2001
From: Kirill <117719052+KirillFirsof@users.noreply.github.com>
Date: Tue, 26 Dec 2023 16:23:38 +0400
Subject: [PATCH] =?UTF-8?q?serilog=20=D0=BC=D0=B5=D0=BD=D1=8F=20=D1=83?=
=?UTF-8?q?=D0=B1=D0=B8=D0=B2=D0=B0=D0=B5=D1=82,=20=D0=BF=D0=BE=D0=BC?=
=?UTF-8?q?=D0=BE=D0=B3=D0=B8=D1=82=D0=B5?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../FormTractorCollection.cs | 8 ++---
.../RPP_FirstLaba_Tractor/Program.cs | 29 ++++++++++++-------
.../ProjectTractor.csproj | 16 +++++++++-
.../RPP_FirstLaba_Tractor/appSettings.json | 20 +++++++++++++
.../RPP_FirstLaba_Tractor/nlog.config | 14 ---------
.../RPP_FirstLaba_Tractor/набор №1.txt | 3 +-
6 files changed, 59 insertions(+), 31 deletions(-)
create mode 100644 RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/appSettings.json
delete mode 100644 RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/nlog.config
diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs
index 9a82ed0..831db09 100644
--- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs
+++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs
@@ -12,6 +12,9 @@ using ProjectTractor.DrawningObjects;
using ProjectTractor.Generics;
using ProjectTractor.MovementStrategy;
using ProjectTractor.Exceptions;
+using Microsoft.VisualBasic.Logging;
+using System.Xml.Linq;
+using System.Linq.Expressions;
namespace ProjectTractor
{
@@ -23,9 +26,7 @@ namespace ProjectTractor
///
///
private readonly TractorsGenericStorage _storage;
- ///
- /// Логер
- ///
+
private readonly ILogger _logger;
///
@@ -36,7 +37,6 @@ namespace ProjectTractor
InitializeComponent();
_storage = new TractorsGenericStorage(pictureBoxCollection.Width,
pictureBoxCollection.Height);
- _logger = logger;
}
///
/// Заполнение listBoxObjects
diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/Program.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/Program.cs
index 95fe589..94e4901 100644
--- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/Program.cs
+++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/Program.cs
@@ -1,14 +1,13 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
-using NLog.Extensions.Logging;
+using Microsoft.Extensions.Configuration;
+using Serilog;
+
namespace ProjectTractor
{
internal static class Program
{
- ///
- /// The main entry point for the application.
- ///
[STAThread]
static void Main()
{
@@ -17,20 +16,30 @@ namespace ProjectTractor
ApplicationConfiguration.Initialize();
var services = new ServiceCollection();
ConfigureServices(services);
- using (ServiceProvider serviceProvider =
- services.BuildServiceProvider())
+ using (ServiceProvider serviceProvider = services.BuildServiceProvider())
{
-
Application.Run(serviceProvider.GetRequiredService());
}
}
private static void ConfigureServices(ServiceCollection services)
{
- services.AddSingleton()
- .AddLogging(option =>
+ 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("appsettings.json")
+ .AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", true)
+ .Build();
+
+ var logger = new LoggerConfiguration().ReadFrom.Configuration(configuration).CreateLogger();
option.SetMinimumLevel(LogLevel.Information);
- option.AddNLog("nlog.config");
+ option.AddSerilog(logger);
});
}
}
diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/ProjectTractor.csproj b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/ProjectTractor.csproj
index 028d1c0..83002d2 100644
--- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/ProjectTractor.csproj
+++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/ProjectTractor.csproj
@@ -9,8 +9,14 @@
+
+
+
-
+
+
+
+
@@ -28,4 +34,12 @@
+
+
+ Always
+
+
+
+
+
\ No newline at end of file
diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/appSettings.json b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/appSettings.json
new file mode 100644
index 0000000..d459679
--- /dev/null
+++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/appSettings.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": "DoubleDeckerBus"
+ }
+ }
+}
\ No newline at end of file
diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/nlog.config b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/nlog.config
deleted file mode 100644
index 249507c..0000000
--- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/nlog.config
+++ /dev/null
@@ -1,14 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/набор №1.txt b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/набор №1.txt
index f0efeb4..2a94cf2 100644
--- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/набор №1.txt
+++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/набор №1.txt
@@ -1,4 +1,3 @@
TractorStorage
-gg|100:100:Yellow;100:100:Blue:Green:True:True;
-ii|100:100:Purple:Green:True:True;100:100:Red:Yellow:True:True;
+gg|100:100:White;100:100:White;100:100:White;100:100:White;100:100:White;100:100:White;100:100:White;100:100:White;100:100:White;100:100:White;100:100:White;100:100:White;100:100:Green:Purple:True:True;100:100:Yellow;100:100:White;