diff --git a/Monorail/Monorail/FormMonorailCollection.cs b/Monorail/Monorail/FormMonorailCollection.cs index 18cfdc3..9ae6367 100644 --- a/Monorail/Monorail/FormMonorailCollection.cs +++ b/Monorail/Monorail/FormMonorailCollection.cs @@ -14,20 +14,19 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Xml.Linq; +using Serilog; namespace Monorail { public partial class FormMonorailCollection : Form { private readonly MonorailGenericStorage _storage; - private readonly ILogger _logger; - public FormMonorailCollection(ILogger logger) + public FormMonorailCollection() { InitializeComponent(); _storage = new MonorailGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height); - _logger = logger; } private void ReloadObjects() @@ -72,7 +71,7 @@ namespace Monorail { bool q = obj + m; MessageBox.Show("Объект добавлен"); - _logger.LogInformation($"Добавлен объект в коллекцию {listBoxStorages.SelectedItem.ToString() ?? string.Empty}"); + Log.Information($"Добавлен объект в коллекцию {listBoxStorages.SelectedItem.ToString() ?? string.Empty}"); m.ChangePictureBoxSize(pictureBoxCollection.Width, pictureBoxCollection.Height); pictureBoxCollection.Image = obj.ShowMonorails(); } @@ -107,7 +106,7 @@ namespace Monorail int pos = Convert.ToInt32(maskedTextBox.Text); var q = obj - pos; MessageBox.Show("Объект удален"); - _logger.LogInformation($"Удален объект из коллекции {listBoxStorages.SelectedItem.ToString() ?? string.Empty} по номеру {pos}"); + Log.Information($"Удален объект из коллекции {listBoxStorages.SelectedItem.ToString() ?? string.Empty} по номеру {pos}"); pictureBoxCollection.Image = obj.ShowMonorails(); } catch (MonorailNotFoundException ex) @@ -155,7 +154,7 @@ MessageBoxIcon.Question) == DialogResult.Yes) ?? string.Empty; _storage.DelSet(name); ReloadObjects(); - _logger.LogInformation($"Удален набор: {name}"); + Log.Information($"Удален набор: {name}"); } } @@ -170,7 +169,7 @@ MessageBoxIcon.Question) == DialogResult.Yes) } _storage.AddSet(storageAddNameBox.Text); ReloadObjects(); - _logger.LogInformation($"Добавлен набор: {storageAddNameBox.Text}"); + Log.Information($"Добавлен набор: {storageAddNameBox.Text}"); } private void SaveToolStripMenuItem_Click(object sender, EventArgs e) @@ -182,7 +181,7 @@ MessageBoxIcon.Question) == DialogResult.Yes) _storage.SaveData(saveFileDialog.FileName); MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); - _logger.LogInformation($"Файл {saveFileDialog.FileName} успешно сохранен"); + Log.Information($"Файл {saveFileDialog.FileName} успешно сохранен"); } catch (Exception ex) { @@ -202,11 +201,12 @@ MessageBoxIcon.Question) == DialogResult.Yes) _storage.LoadData(openFileDialog.FileName); MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); - _logger.LogInformation($"Файл {openFileDialog.FileName} успешно загружен"); + Log.Information($"Файл {openFileDialog.FileName} успешно загружен"); foreach (var collection in _storage.Keys) { listBoxStorages.Items.Add(collection); } + ReloadObjects(); } catch (Exception ex) { diff --git a/Monorail/Monorail/Monorail.csproj b/Monorail/Monorail/Monorail.csproj index 9aebb36..7271e69 100644 --- a/Monorail/Monorail/Monorail.csproj +++ b/Monorail/Monorail/Monorail.csproj @@ -9,6 +9,8 @@ + + @@ -26,10 +28,4 @@ - - - Always - - - \ No newline at end of file diff --git a/Monorail/Monorail/Program.cs b/Monorail/Monorail/Program.cs index d23d4e6..5a4cf29 100644 --- a/Monorail/Monorail/Program.cs +++ b/Monorail/Monorail/Program.cs @@ -8,36 +8,28 @@ using System.Drawing; using System.Linq; using System.Threading.Tasks; using System.Windows.Forms; +using Serilog; +using Serilog.Events; +using Serilog.Formatting.Json; namespace Monorail { internal static class Program { /// - /// The main entry point for the application. + /// The main entry point for the application. /// [STAThread] static void Main() { - - 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"); - }); + Log.Logger = new LoggerConfiguration() + .WriteTo.File("log.txt") + .MinimumLevel.Debug() + .CreateLogger(); + Application.SetHighDpiMode(HighDpiMode.SystemAware); + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new FormMonorailCollection()); } } } diff --git a/Monorail/Monorail/log.txt b/Monorail/Monorail/log.txt new file mode 100644 index 0000000..e69de29 diff --git a/Monorail/Monorail/nlog.config b/Monorail/Monorail/nlog.config deleted file mode 100644 index f35d051..0000000 --- a/Monorail/Monorail/nlog.config +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file