From 1739ded8c2275edfd041876d91ae17991f382e2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9E=D0=BB=D0=B5=D0=B3=20=D0=9A=D1=83=D0=B4=D1=80=D0=B8?= =?UTF-8?q?=D0=BD=D1=81=D0=BA=D0=B8=D0=B9?= Date: Sat, 4 May 2024 22:46:20 +0400 Subject: [PATCH] wip --- .../AbstractCompany.cs | 5 ++++ .../ProjectContainerShip/Program.cs | 29 ++++++++++++++----- .../ProjectContainerShip.csproj | 19 +++++++++++- .../ProjectContainerShip/serilog.json | 15 ++++++++++ 4 files changed, 60 insertions(+), 8 deletions(-) create mode 100644 ProjectContainerShip/ProjectContainerShip/serilog.json diff --git a/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/AbstractCompany.cs b/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/AbstractCompany.cs index 04860eb..c8ab9b6 100644 --- a/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/AbstractCompany.cs +++ b/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/AbstractCompany.cs @@ -1,4 +1,5 @@ using ProjectContainerShip.Drawings; +using System.Linq.Expressions; namespace ProjectContainerShip.CollectionGenericObjects; /// @@ -94,8 +95,12 @@ namespace ProjectContainerShip.CollectionGenericObjects; SetObjectsPosition(); for (int i = 0; i < (_collection?.Count ?? 0); ++i) { + try + { DrawningShip? obj = _collection?.Get(i); obj?.DrawTransport(graphics); + } + catch (Exception) { } } return bitmap; } diff --git a/ProjectContainerShip/ProjectContainerShip/Program.cs b/ProjectContainerShip/ProjectContainerShip/Program.cs index b43f2dc..e4d028b 100644 --- a/ProjectContainerShip/ProjectContainerShip/Program.cs +++ b/ProjectContainerShip/ProjectContainerShip/Program.cs @@ -1,5 +1,7 @@ +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; +using Serilog; namespace ProjectContainerShip { @@ -13,9 +15,12 @@ namespace ProjectContainerShip { // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. - ServiceCollection services = new(); ApplicationConfiguration.Initialize(); - Application.Run(new FormShipCollection()); + + ServiceCollection services = new(); + ConfigureServices(services); + using ServiceProvider serviceProvider = services.BuildServiceProvider(); + Application.Run(serviceProvider.GetRequiredService()); } /// @@ -24,12 +29,22 @@ namespace ProjectContainerShip /// private static void ConfigureServices(ServiceCollection services) { + string[] path = Directory.GetCurrentDirectory().Split('\\'); + string pathNeed = ""; + for (int i = 0; i < path.Length - 3; i++) + { + pathNeed += path[i] + "\\"; + } services.AddSingleton() - .AddLogging(option => - { - option.SetMinimumLevel(LogLevel.Information); - option.AddNLog("nlog.config"); - }); + .AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + option.AddSerilog(new LoggerConfiguration() + .ReadFrom.Configuration(new ConfigurationBuilder() + .AddJsonFile($"{pathNeed}serilog.json") + .Build()) + .CreateLogger()); + }); } } } \ No newline at end of file diff --git a/ProjectContainerShip/ProjectContainerShip/ProjectContainerShip.csproj b/ProjectContainerShip/ProjectContainerShip/ProjectContainerShip.csproj index e8ccf4b..18c8538 100644 --- a/ProjectContainerShip/ProjectContainerShip/ProjectContainerShip.csproj +++ b/ProjectContainerShip/ProjectContainerShip/ProjectContainerShip.csproj @@ -9,7 +9,18 @@ - + + + + + + + + + + + + @@ -27,4 +38,10 @@ + + + Always + + + \ No newline at end of file diff --git a/ProjectContainerShip/ProjectContainerShip/serilog.json b/ProjectContainerShip/ProjectContainerShip/serilog.json new file mode 100644 index 0000000..a7878e1 --- /dev/null +++ b/ProjectContainerShip/ProjectContainerShip/serilog.json @@ -0,0 +1,15 @@ +{ + "Serilog": { + "Using": [ "Serilog.Sinks.File" ], + "MinimumLevel": "Debug", + "WriteTo": [ + { + "Name": "File", + "Args": { "path": "log.log" } + } + ], + "Properties": { + "Application": "Sample" + } + } +}