From 0091fe4a9201ce18793a0b0adf12e639e4080a5e Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Sun, 4 Dec 2022 14:11:37 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D1=85=D0=BE=D0=B4=20?= =?UTF-8?q?=D0=BD=D0=B0=20Serilog?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Catamaran/App.config | 60 +++++++------ Catamaran/Catamaran.csproj | 100 ++++++++++++++++++++-- Catamaran/FormMapWithSetBoats.Designer.cs | 24 +++--- Catamaran/Program.cs | 17 ++-- Catamaran/appsettings.json | 20 +++++ Catamaran/nlog.config | 13 --- Catamaran/packages.config | 29 ++++++- 7 files changed, 194 insertions(+), 69 deletions(-) create mode 100644 Catamaran/appsettings.json delete mode 100644 Catamaran/nlog.config diff --git a/Catamaran/App.config b/Catamaran/App.config index 2744ee6..886bf17 100644 --- a/Catamaran/App.config +++ b/Catamaran/App.config @@ -1,57 +1,65 @@ - + - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + + + + + + + + + diff --git a/Catamaran/Catamaran.csproj b/Catamaran/Catamaran.csproj index 40a6757..14a9808 100644 --- a/Catamaran/Catamaran.csproj +++ b/Catamaran/Catamaran.csproj @@ -43,8 +43,20 @@ packages\Microsoft.Bcl.AsyncInterfaces.7.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll - - packages\Microsoft.Extensions.Configuration.Abstractions.2.1.0\lib\netstandard2.0\Microsoft.Extensions.Configuration.Abstractions.dll + + packages\Microsoft.Extensions.Configuration.7.0.0\lib\net462\Microsoft.Extensions.Configuration.dll + + + packages\Microsoft.Extensions.Configuration.Abstractions.7.0.0\lib\net462\Microsoft.Extensions.Configuration.Abstractions.dll + + + packages\Microsoft.Extensions.Configuration.Binder.2.0.0\lib\netstandard2.0\Microsoft.Extensions.Configuration.Binder.dll + + + packages\Microsoft.Extensions.Configuration.FileExtensions.7.0.0\lib\net462\Microsoft.Extensions.Configuration.FileExtensions.dll + + + packages\Microsoft.Extensions.Configuration.Json.7.0.0\lib\net462\Microsoft.Extensions.Configuration.Json.dll packages\Microsoft.Extensions.DependencyInjection.7.0.0\lib\net462\Microsoft.Extensions.DependencyInjection.dll @@ -52,6 +64,18 @@ packages\Microsoft.Extensions.DependencyInjection.Abstractions.7.0.0\lib\net462\Microsoft.Extensions.DependencyInjection.Abstractions.dll + + packages\Microsoft.Extensions.DependencyModel.3.0.0\lib\net451\Microsoft.Extensions.DependencyModel.dll + + + packages\Microsoft.Extensions.FileProviders.Abstractions.7.0.0\lib\net462\Microsoft.Extensions.FileProviders.Abstractions.dll + + + packages\Microsoft.Extensions.FileProviders.Physical.7.0.0\lib\net462\Microsoft.Extensions.FileProviders.Physical.dll + + + packages\Microsoft.Extensions.FileSystemGlobbing.7.0.0\lib\net462\Microsoft.Extensions.FileSystemGlobbing.dll + packages\Microsoft.Extensions.Logging.7.0.0\lib\net462\Microsoft.Extensions.Logging.dll @@ -64,6 +88,9 @@ packages\Microsoft.Extensions.Primitives.7.0.0\lib\net462\Microsoft.Extensions.Primitives.dll + + packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll + packages\NLog.5.0.5\lib\net46\NLog.dll @@ -71,21 +98,37 @@ packages\NLog.Extensions.Logging.5.1.0\lib\net461\NLog.Extensions.Logging.dll - packages\Serilog.2.9.0\lib\net46\Serilog.dll + packages\Serilog.2.10.0\lib\net46\Serilog.dll packages\Serilog.Extensions.Logging.3.1.0\lib\netstandard2.0\Serilog.Extensions.Logging.dll + + packages\Serilog.Settings.Configuration.3.4.0\lib\net461\Serilog.Settings.Configuration.dll + + + packages\Serilog.Sinks.File.5.0.0\lib\net45\Serilog.Sinks.File.dll + packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll + + + packages\System.Configuration.ConfigurationManager.7.0.0\lib\net462\System.Configuration.ConfigurationManager.dll + + packages\System.Diagnostics.DiagnosticSource.7.0.0\lib\net462\System.Diagnostics.DiagnosticSource.dll + + packages\System.IO.4.3.0\lib\net462\System.IO.dll + True + True + packages\System.Memory.4.5.5\lib\net461\System.Memory.dll @@ -93,22 +136,60 @@ packages\System.Memory.Data.1.0.2\lib\net461\System.Memory.Data.dll + packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll + + packages\System.Runtime.4.3.0\lib\net462\System.Runtime.dll + True + True + packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll - - packages\System.Text.Encodings.Web.4.7.2\lib\net461\System.Text.Encodings.Web.dll + + packages\System.Runtime.InteropServices.RuntimeInformation.4.0.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll + True + True - - packages\System.Text.Json.4.6.0\lib\net461\System.Text.Json.dll + + + packages\System.Security.AccessControl.6.0.0\lib\net461\System.Security.AccessControl.dll + + + packages\System.Security.Cryptography.Algorithms.4.3.1\lib\net463\System.Security.Cryptography.Algorithms.dll + True + True + + + packages\System.Security.Cryptography.Encoding.4.3.0\lib\net46\System.Security.Cryptography.Encoding.dll + True + True + + + packages\System.Security.Cryptography.Primitives.4.3.0\lib\net46\System.Security.Cryptography.Primitives.dll + True + True + + + packages\System.Security.Permissions.7.0.0\lib\net462\System.Security.Permissions.dll + + + packages\System.Security.Principal.Windows.5.0.0\lib\net461\System.Security.Principal.Windows.dll + + + + packages\System.Text.Encodings.Web.7.0.0\lib\net462\System.Text.Encodings.Web.dll + + + packages\System.Text.Json.7.0.0\lib\net462\System.Text.Json.dll packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll + packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll @@ -121,6 +202,7 @@ + @@ -178,7 +260,9 @@ Resources.resx True - + + Always + SettingsSingleFileGenerator diff --git a/Catamaran/FormMapWithSetBoats.Designer.cs b/Catamaran/FormMapWithSetBoats.Designer.cs index 78eac40..110326b 100644 --- a/Catamaran/FormMapWithSetBoats.Designer.cs +++ b/Catamaran/FormMapWithSetBoats.Designer.cs @@ -70,9 +70,9 @@ this.groupBoxTools.Controls.Add(this.buttonUp); this.groupBoxTools.Controls.Add(this.buttonDown); this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right; - this.groupBoxTools.Location = new System.Drawing.Point(653, 33); + this.groupBoxTools.Location = new System.Drawing.Point(653, 36); this.groupBoxTools.Name = "groupBoxTools"; - this.groupBoxTools.Size = new System.Drawing.Size(303, 614); + this.groupBoxTools.Size = new System.Drawing.Size(303, 611); this.groupBoxTools.TabIndex = 0; this.groupBoxTools.TabStop = false; this.groupBoxTools.Text = "Tools"; @@ -192,7 +192,7 @@ this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonLeft.BackgroundImage = global::Catamaran.Properties.Resources.Left; this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; - this.buttonLeft.Location = new System.Drawing.Point(10, 529); + this.buttonLeft.Location = new System.Drawing.Point(10, 526); this.buttonLeft.Name = "buttonLeft"; this.buttonLeft.Size = new System.Drawing.Size(30, 30); this.buttonLeft.TabIndex = 4; @@ -204,7 +204,7 @@ this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonRight.BackgroundImage = global::Catamaran.Properties.Resources.Right; this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; - this.buttonRight.Location = new System.Drawing.Point(70, 529); + this.buttonRight.Location = new System.Drawing.Point(70, 526); this.buttonRight.Name = "buttonRight"; this.buttonRight.Size = new System.Drawing.Size(30, 30); this.buttonRight.TabIndex = 5; @@ -216,7 +216,7 @@ this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonUp.BackgroundImage = global::Catamaran.Properties.Resources.Up; this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; - this.buttonUp.Location = new System.Drawing.Point(40, 507); + this.buttonUp.Location = new System.Drawing.Point(40, 504); this.buttonUp.Name = "buttonUp"; this.buttonUp.Size = new System.Drawing.Size(30, 30); this.buttonUp.TabIndex = 2; @@ -228,7 +228,7 @@ this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonDown.BackgroundImage = global::Catamaran.Properties.Resources.Down; this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; - this.buttonDown.Location = new System.Drawing.Point(40, 537); + this.buttonDown.Location = new System.Drawing.Point(40, 534); this.buttonDown.Name = "buttonDown"; this.buttonDown.Size = new System.Drawing.Size(30, 30); this.buttonDown.TabIndex = 3; @@ -238,9 +238,9 @@ // pictureBox // this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill; - this.pictureBox.Location = new System.Drawing.Point(0, 33); + this.pictureBox.Location = new System.Drawing.Point(0, 36); this.pictureBox.Name = "pictureBox"; - this.pictureBox.Size = new System.Drawing.Size(653, 614); + this.pictureBox.Size = new System.Drawing.Size(653, 611); this.pictureBox.TabIndex = 1; this.pictureBox.TabStop = false; // @@ -252,7 +252,7 @@ this.fileToolStripMenuItem}); this.menuStrip.Location = new System.Drawing.Point(0, 0); this.menuStrip.Name = "menuStrip"; - this.menuStrip.Size = new System.Drawing.Size(956, 33); + this.menuStrip.Size = new System.Drawing.Size(956, 36); this.menuStrip.TabIndex = 2; this.menuStrip.Text = "menuStrip"; // @@ -262,20 +262,20 @@ this.saveToolStripMenuItem, this.loadToolStripMenuItem}); this.fileToolStripMenuItem.Name = "fileToolStripMenuItem"; - this.fileToolStripMenuItem.Size = new System.Drawing.Size(54, 29); + this.fileToolStripMenuItem.Size = new System.Drawing.Size(54, 32); this.fileToolStripMenuItem.Text = "File"; // // saveToolStripMenuItem // this.saveToolStripMenuItem.Name = "saveToolStripMenuItem"; - this.saveToolStripMenuItem.Size = new System.Drawing.Size(270, 34); + this.saveToolStripMenuItem.Size = new System.Drawing.Size(153, 34); this.saveToolStripMenuItem.Text = "Save"; this.saveToolStripMenuItem.Click += new System.EventHandler(this.saveToolStripMenuItem_Click); // // loadToolStripMenuItem // this.loadToolStripMenuItem.Name = "loadToolStripMenuItem"; - this.loadToolStripMenuItem.Size = new System.Drawing.Size(270, 34); + this.loadToolStripMenuItem.Size = new System.Drawing.Size(153, 34); this.loadToolStripMenuItem.Text = "Load"; this.loadToolStripMenuItem.Click += new System.EventHandler(this.loadToolStripMenuItem_Click); // diff --git a/Catamaran/Program.cs b/Catamaran/Program.cs index a331085..4f339df 100644 --- a/Catamaran/Program.cs +++ b/Catamaran/Program.cs @@ -1,11 +1,14 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Threading.Tasks; using System.Windows.Forms; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; -using NLog.Extensions.Logging; +using Microsoft.Extensions.Configuration; + +using Serilog; namespace Catamaran { @@ -30,11 +33,13 @@ namespace Catamaran private static void ConfigureServices(ServiceCollection services) { services.AddSingleton() - .AddLogging(option => - { - option.SetMinimumLevel(LogLevel.Information); - option.AddNLog("nlog.config"); - }); + .AddLogging(option => + { + var configuration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile(path: "appsettings.json", optional: false, reloadOnChange: true).Build(); + var logger = new LoggerConfiguration().ReadFrom.Configuration(configuration).CreateLogger(); + option.SetMinimumLevel(LogLevel.Information); + option.AddSerilog(logger); + }); } } } diff --git a/Catamaran/appsettings.json b/Catamaran/appsettings.json new file mode 100644 index 0000000..433478a --- /dev/null +++ b/Catamaran/appsettings.json @@ -0,0 +1,20 @@ +{ + "Serilog": { + "Using": [ "Serilog.Sinks.File" ], + "MinimumLevel": "Debug", + "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": "Catamaran" + } + } +} diff --git a/Catamaran/nlog.config b/Catamaran/nlog.config deleted file mode 100644 index 65761ee..0000000 --- a/Catamaran/nlog.config +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/Catamaran/packages.config b/Catamaran/packages.config index 258ab16..1d3fde4 100644 --- a/Catamaran/packages.config +++ b/Catamaran/packages.config @@ -3,25 +3,46 @@ - + + + + + + + + + + - + + + + + + - - + + + + + + + + + \ No newline at end of file