From 72369a6507477e6d988401b2f964de262f4ff85a Mon Sep 17 00:00:00 2001 From: Lior Banai Date: Wed, 15 Nov 2023 12:21:24 +0200 Subject: [PATCH] Update To NET8 --- ...logy.LogServer.Clients.Test.Console.csproj | 4 +- .../Program.cs | 8 +-- .../Analogy.LogServer.Clients.csproj | 12 ++-- .../NetCore/AnalogyMessageConsumer.cs | 4 +- .../NetCore/AnalogyMessageProducer.cs | 10 +-- .../Netframework/AnalogyMessageConsumer.cs | 7 +- .../Netframework/AnalogyMessageProducer.cs | 8 +-- .../Analogy.LogServer.Configurator.csproj | 8 +-- .../EventLogsSettings.cs | 16 ++--- Analogy.LogServer.Configurator/MainForm.cs | 20 +++--- Analogy.LogServer.Configurator/Program.cs | 6 +- .../ServerConfigurationManager.cs | 16 ++--- .../ServiceConfiguration.cs | 7 +- .../Analogy.LogServer.Tests.csproj | 8 +-- Analogy.LogServer.Tests/Program.cs | 2 +- Analogy.LogServer.Tests/TestForm.cs | 3 +- Analogy.LogServer/Analogy.LogServer.csproj | 24 ++++--- .../Controllers/MessagesController.cs | 8 +-- Analogy.LogServer/GRPCLogConsumer.cs | 11 +--- Analogy.LogServer/Interfaces/ILogConsumer.cs | 2 +- Analogy.LogServer/LogFileConsumer.cs | 3 +- Analogy.LogServer/MessageHistoryContainer.cs | 7 +- Analogy.LogServer/MessagesContainer.cs | 10 ++- Analogy.LogServer/Program.cs | 6 +- Analogy.LogServer/ServiceConfiguration.cs | 8 +-- Analogy.LogServer/Services/CleanUpWorker.cs | 4 +- Analogy.LogServer/Services/GreeterService.cs | 15 ++--- .../Services/WindowsEventLogsMonitor.cs | 12 ++-- Analogy.LogServer/Startup.cs | 6 +- Analogy.LogServer/Utils.cs | 6 +- BannedSymbols.txt | 9 +++ Directory.Build.props | 64 +++++++++++++++++++ 32 files changed, 184 insertions(+), 150 deletions(-) create mode 100644 BannedSymbols.txt create mode 100644 Directory.Build.props diff --git a/Analogy.LogServer.Clients.Test.Console/Analogy.LogServer.Clients.Test.Console.csproj b/Analogy.LogServer.Clients.Test.Console/Analogy.LogServer.Clients.Test.Console.csproj index 0abfd721..97916f7f 100644 --- a/Analogy.LogServer.Clients.Test.Console/Analogy.LogServer.Clients.Test.Console.csproj +++ b/Analogy.LogServer.Clients.Test.Console/Analogy.LogServer.Clients.Test.Console.csproj @@ -5,8 +5,8 @@ net7.0-windows;net6.0-windows;net48;net471 - - + + diff --git a/Analogy.LogServer.Clients.Test.Console/Program.cs b/Analogy.LogServer.Clients.Test.Console/Program.cs index 9380fd6c..ffd5f4b1 100644 --- a/Analogy.LogServer.Clients.Test.Console/Program.cs +++ b/Analogy.LogServer.Clients.Test.Console/Program.cs @@ -8,10 +8,10 @@ namespace Analogy.LogServer.Clients.Test.Console { #if NETCOREAPP3_1 || NET public class Program - { + { public static TargetFrameworkAttribute CurrentFrameworkAttribute => (TargetFrameworkAttribute)Assembly.GetExecutingAssembly().GetCustomAttribute(typeof(TargetFrameworkAttribute)); - static async Task Main(string[] args) + public static async Task Main(string[] args) { string ip = "localhost"; if (args.Length >= 2) @@ -32,7 +32,7 @@ static async Task Main(string[] args) public class Program { public static TargetFrameworkAttribute CurrentFrameworkAttribute => (TargetFrameworkAttribute)Assembly.GetExecutingAssembly().GetCustomAttribute(typeof(TargetFrameworkAttribute)); - static async Task Main(string[] args) + public static async Task Main(string[] args) { string ip = "localhost"; if (args.Length >= 2) @@ -50,4 +50,4 @@ static async Task Main(string[] args) } } #endif -} +} \ No newline at end of file diff --git a/Analogy.LogServer.Clients/Analogy.LogServer.Clients.csproj b/Analogy.LogServer.Clients/Analogy.LogServer.Clients.csproj index 70a3f16e..6e66249e 100644 --- a/Analogy.LogServer.Clients/Analogy.LogServer.Clients.csproj +++ b/Analogy.LogServer.Clients/Analogy.LogServer.Clients.csproj @@ -1,16 +1,16 @@ - net7.0-windows;net6.0-windows;net48;net471 + net8.0-windows;net7.0-windows;net6.0-windows;net48;net471 Library true Lior Banai Analogy.LogViewer grpc client to send messages To Analogy Log Viewer with gRPC server running - Lior Banai @ 2020-2023 + Lior Banai @ 2020-2024 MIT Analogy.gRPC.service.png - 5.0.3.1 + 6.0.0 true true @@ -22,7 +22,7 @@ https://github.com/Analogy-LogViewer/Analogy.LogViewer.gRPC enable latest - + portable @@ -39,7 +39,7 @@ - + @@ -47,7 +47,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/Analogy.LogServer.Clients/NetCore/AnalogyMessageConsumer.cs b/Analogy.LogServer.Clients/NetCore/AnalogyMessageConsumer.cs index f8f352c4..557869ad 100644 --- a/Analogy.LogServer.Clients/NetCore/AnalogyMessageConsumer.cs +++ b/Analogy.LogServer.Clients/NetCore/AnalogyMessageConsumer.cs @@ -41,7 +41,6 @@ public AnalogyMessageConsumer(string address) var token = _cts.Token; Interfaces.AnalogyLogMessage msg = new Interfaces.AnalogyLogMessage() { - Level = (AnalogyLogLevel)m.Level, Class = (AnalogyLogClass)m.Class, Date = m.Date.ToDateTime().ToLocalTime(), @@ -54,7 +53,7 @@ public AnalogyMessageConsumer(string address) Source = m.Source, Text = m.Text, ThreadId = m.ThreadId, - User = m.User + User = m.User, }; if (!string.IsNullOrEmpty(m.Category)) { @@ -74,7 +73,6 @@ public Task Stop() { _cts?.Cancel(); return channel.ShutdownAsync(); - } public void Dispose() diff --git a/Analogy.LogServer.Clients/NetCore/AnalogyMessageProducer.cs b/Analogy.LogServer.Clients/NetCore/AnalogyMessageProducer.cs index 65023782..bc2ee59c 100644 --- a/Analogy.LogServer.Clients/NetCore/AnalogyMessageProducer.cs +++ b/Analogy.LogServer.Clients/NetCore/AnalogyMessageProducer.cs @@ -26,9 +26,7 @@ static AnalogyMessageProducer() { AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); } - /// - /// - /// + /// The address. for example: http://localhost:6000 public AnalogyMessageProducer(string address) { @@ -42,7 +40,6 @@ public AnalogyMessageProducer(string address) { OnError?.Invoke(this, $"Error creating gRPC Connection: {e}"); } - } public async Task Log(string text, string source, AnalogyLogLevel level, string category = "", @@ -83,7 +80,6 @@ public async Task Log(string text, string source, AnalogyLogLevel level, string { await _semaphoreSlim.WaitAsync(); await stream.RequestStream.WriteAsync(m); - } catch (Exception e) { @@ -134,9 +130,7 @@ public void StopReceiving() catch (Exception e) { OnError?.Invoke(this, $"Error closing gRPC connection to Server: {e}"); - } - } public async Task StopReceivingAsync() { @@ -147,9 +141,7 @@ public async Task StopReceivingAsync() catch (Exception e) { OnError?.Invoke(this, $"Error closing gRPC connection to Server: {e}"); - } - } public void Dispose() diff --git a/Analogy.LogServer.Clients/Netframework/AnalogyMessageConsumer.cs b/Analogy.LogServer.Clients/Netframework/AnalogyMessageConsumer.cs index 26e9b238..502c1ba7 100644 --- a/Analogy.LogServer.Clients/Netframework/AnalogyMessageConsumer.cs +++ b/Analogy.LogServer.Clients/Netframework/AnalogyMessageConsumer.cs @@ -43,7 +43,6 @@ private async Task GetMessages() var token = _cts.Token; Interfaces.AnalogyLogMessage msg = new Interfaces.AnalogyLogMessage() { - Level = (AnalogyLogLevel)m.Level, Class = (AnalogyLogClass)m.Class, Date = m.Date.ToDateTime().ToLocalTime(), @@ -56,7 +55,7 @@ private async Task GetMessages() Source = m.Source, Text = m.Text, ThreadId = m.ThreadId, - User = m.User + User = m.User, }; if (!string.IsNullOrEmpty(m.Category)) { @@ -76,7 +75,6 @@ private async Task GetMessages() { OnError?.Invoke(this, e.Message); } - } public async Task Stop() { @@ -90,8 +88,7 @@ public void Dispose() _cts?.Cancel(); _cts?.Dispose(); _stream?.Dispose(); - channel?.ShutdownAsync(); - + _ = channel?.ShutdownAsync(); } } } diff --git a/Analogy.LogServer.Clients/Netframework/AnalogyMessageProducer.cs b/Analogy.LogServer.Clients/Netframework/AnalogyMessageProducer.cs index 5c2bf142..69245c8d 100644 --- a/Analogy.LogServer.Clients/Netframework/AnalogyMessageProducer.cs +++ b/Analogy.LogServer.Clients/Netframework/AnalogyMessageProducer.cs @@ -39,7 +39,6 @@ public AnalogyMessageProducer(string address) { OnError?.Invoke(this, $"Error creating gRPC Connection: {e.Message}"); } - } public async Task Log(string text, string source, AnalogyLogLevel level, string category = "", @@ -80,7 +79,6 @@ public async Task Log(string text, string source, AnalogyLogLevel level, string { await _semaphoreSlim.WaitAsync(); await stream.RequestStream.WriteAsync(m); - } catch (Exception e) { @@ -131,9 +129,7 @@ public void StopReceiving() catch (Exception e) { OnError?.Invoke(this, $"Error closing gRPC connection to Server: {e.Message}"); - } - } public async Task StopReceivingAsync() { @@ -144,16 +140,14 @@ public async Task StopReceivingAsync() catch (Exception e) { OnError?.Invoke(this, $"Error closing gRPC connection to Server: {e}"); - } - } public void Dispose() { try { _semaphoreSlim.Dispose(); - channel?.ShutdownAsync(); + _ = (channel?.ShutdownAsync()); stream?.Dispose(); } catch (Exception e) diff --git a/Analogy.LogServer.Configurator/Analogy.LogServer.Configurator.csproj b/Analogy.LogServer.Configurator/Analogy.LogServer.Configurator.csproj index e5f2fd23..cdd6cc50 100644 --- a/Analogy.LogServer.Configurator/Analogy.LogServer.Configurator.csproj +++ b/Analogy.LogServer.Configurator/Analogy.LogServer.Configurator.csproj @@ -2,7 +2,7 @@ WinExe - net7.0-windows;net6.0-windows;net48;net471 + net8.0-windows;net7.0-windows;net6.0-windows;net48;net471 true true Lior Banai @@ -16,13 +16,13 @@ snupkg 0.0.3 true - Lior Banai @ 2020-2023 + Lior Banai @ 2020-2024 Analogy.gRPC.service.png true - + all @@ -32,7 +32,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/Analogy.LogServer.Configurator/EventLogsSettings.cs b/Analogy.LogServer.Configurator/EventLogsSettings.cs index fa5ecd4d..0c251102 100644 --- a/Analogy.LogServer.Configurator/EventLogsSettings.cs +++ b/Analogy.LogServer.Configurator/EventLogsSettings.cs @@ -1,10 +1,10 @@ -using System; +using Analogy.LogServer.Configurator; +using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Windows.Forms; -using Analogy.LogServer.Configurator; namespace Analogy.LogViewer.WindowsEventLogs { @@ -16,10 +16,10 @@ public EventLogsSettings() { InitializeComponent(); } - public EventLogsSettings(ServerConfiguration configuration):this() - { - Configuration = configuration; - } + public EventLogsSettings(ServerConfiguration configuration) : this() + { + Configuration = configuration; + } private void btnAdd_Click(object sender, EventArgs e) { List selected = lstAvailable.SelectedItems.Cast().ToList(); @@ -43,7 +43,7 @@ private void btnRemove_Click(object sender, EventArgs e) } private void UpdateUserSettingList() { - Configuration.ServiceConfiguration.WindowsEventLogsConfiguration.LogsToMonitor= lstSelected.Items.Cast().ToList(); + Configuration.ServiceConfiguration.WindowsEventLogsConfiguration.LogsToMonitor = lstSelected.Items.Cast().ToList(); } private void EventLogsSettings_Load(object sender, EventArgs e) @@ -61,4 +61,4 @@ private void EventLogsSettings_Load(object sender, EventArgs e) } } } -} +} \ No newline at end of file diff --git a/Analogy.LogServer.Configurator/MainForm.cs b/Analogy.LogServer.Configurator/MainForm.cs index 124c56a1..a5e78a56 100644 --- a/Analogy.LogServer.Configurator/MainForm.cs +++ b/Analogy.LogServer.Configurator/MainForm.cs @@ -1,4 +1,6 @@ -using System; +using Analogy.LogViewer.WindowsEventLogs; +using Newtonsoft.Json.Linq; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -7,8 +9,6 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; -using Analogy.LogViewer.WindowsEventLogs; -using Newtonsoft.Json.Linq; namespace Analogy.LogServer.Configurator { @@ -33,7 +33,7 @@ private void MainForm_Load(object sender, EventArgs e) return; } - EventLogsSettings els=new EventLogsSettings(ServiceConfiguration); + EventLogsSettings els = new EventLogsSettings(ServiceConfiguration); gbWindowsEventsLog.Controls.Add(els); els.Dock = DockStyle.Fill; LoadSettings(); @@ -52,11 +52,11 @@ private void LoadSettings() private void SaveSettings() { ServiceConfiguration.ServiceConfiguration.LogAlsoToLogFile = chLogToFile.Checked; - ServiceConfiguration.Serilog.WriteTo[1].Args.pathFormat=txtbLogFileLocation.Text; - ServiceConfiguration.ServiceConfiguration.HoursToKeepHistory =(int)nudHoursToKeepHistory.Value ; - ServiceConfiguration.ServiceConfiguration.MemoryUsageInMB =(int)nudMemoryUsageInMB.Value; - ServiceConfiguration.ServiceConfiguration.CleanUpIntervalMinutes =(int)nudCleanUpIntervalMinutes.Value; - ServiceConfiguration.ServiceConfiguration.WindowsEventLogsConfiguration.EnableMonitoring=chkbEnableWindowsEventLogs.Checked; + ServiceConfiguration.Serilog.WriteTo[1].Args.pathFormat = txtbLogFileLocation.Text; + ServiceConfiguration.ServiceConfiguration.HoursToKeepHistory = (int)nudHoursToKeepHistory.Value; + ServiceConfiguration.ServiceConfiguration.MemoryUsageInMB = (int)nudMemoryUsageInMB.Value; + ServiceConfiguration.ServiceConfiguration.CleanUpIntervalMinutes = (int)nudCleanUpIntervalMinutes.Value; + ServiceConfiguration.ServiceConfiguration.WindowsEventLogsConfiguration.EnableMonitoring = chkbEnableWindowsEventLogs.Checked; } } -} +} \ No newline at end of file diff --git a/Analogy.LogServer.Configurator/Program.cs b/Analogy.LogServer.Configurator/Program.cs index 35421951..2ea794c1 100644 --- a/Analogy.LogServer.Configurator/Program.cs +++ b/Analogy.LogServer.Configurator/Program.cs @@ -6,13 +6,13 @@ namespace Analogy.LogServer.Configurator { - static class Program + public static class Program { /// /// The main entry point for the application. /// [STAThread] - static void Main() + public static void Main() { #if !NET471 && !NET48 Application.SetHighDpiMode(HighDpiMode.SystemAware); @@ -22,4 +22,4 @@ static void Main() Application.Run(new MainForm()); } } -} +} \ No newline at end of file diff --git a/Analogy.LogServer.Configurator/ServerConfigurationManager.cs b/Analogy.LogServer.Configurator/ServerConfigurationManager.cs index bbfb5740..11ce4b8e 100644 --- a/Analogy.LogServer.Configurator/ServerConfigurationManager.cs +++ b/Analogy.LogServer.Configurator/ServerConfigurationManager.cs @@ -1,9 +1,9 @@ -using System; +using Newtonsoft.Json; +using Newtonsoft.Json.Serialization; +using System; using System.Collections.Generic; using System.IO; using System.Windows.Forms; -using Newtonsoft.Json; -using Newtonsoft.Json.Serialization; namespace Analogy.LogServer.Configurator { @@ -18,13 +18,12 @@ public class ServerConfigurationManager public ServerConfigurationManager() { - try { string data = File.ReadAllText(ServerSettingFile); JsonSerializerSettings settings = new JsonSerializerSettings() { - ContractResolver = new DefaultContractResolver() + ContractResolver = new DefaultContractResolver(), }; ServerConfiguration = JsonConvert.DeserializeObject(data, settings); } @@ -32,14 +31,12 @@ public ServerConfigurationManager() { MessageBox.Show($"Error loading configuration file: {e.Message}"); } - } public void Save() { try { - // serialize JSON directly to a file using (StreamWriter file = File.CreateText(ServerSettingFile)) { @@ -49,9 +46,8 @@ public void Save() } catch (Exception ex) { - MessageBox.Show( $"Unable to save file {ServerSettingFile}: {ex}"); - + MessageBox.Show($"Unable to save file {ServerSettingFile}: {ex}"); } } } -} +} \ No newline at end of file diff --git a/Analogy.LogServer.Configurator/ServiceConfiguration.cs b/Analogy.LogServer.Configurator/ServiceConfiguration.cs index e0497cad..b8534919 100644 --- a/Analogy.LogServer.Configurator/ServiceConfiguration.cs +++ b/Analogy.LogServer.Configurator/ServiceConfiguration.cs @@ -16,13 +16,12 @@ public class ServiceConfiguration public int MemoryUsageInMB { get; set; } public WindowsEventLogsConfiguration WindowsEventLogsConfiguration { get; set; } - + public ServiceConfiguration() { } } - public class WindowsEventLogsConfiguration { public bool EnableMonitoring { get; set; } @@ -31,7 +30,6 @@ public class WindowsEventLogsConfiguration public List LogsToMonitor { get; set; } } - public class Serilog { public object[] Usings { get; set; } @@ -65,5 +63,4 @@ public class Args public string pathFormat { get; set; } public string formatter { get; set; } } - -} +} \ No newline at end of file diff --git a/Analogy.LogServer.Tests/Analogy.LogServer.Tests.csproj b/Analogy.LogServer.Tests/Analogy.LogServer.Tests.csproj index 9d18029a..1be7e276 100644 --- a/Analogy.LogServer.Tests/Analogy.LogServer.Tests.csproj +++ b/Analogy.LogServer.Tests/Analogy.LogServer.Tests.csproj @@ -2,9 +2,9 @@ WinExe - net6.0-windows;net7.0-windows + net8.0-windows;net7.0-windows true - Lior Banai @ 2020 + Lior Banai @ 2020-2024 MIT https://github.com/Analogy-LogViewer/Analogy.LogViewer.gRPC https://github.com/Analogy-LogViewer/Analogy.LogViewer.gRPC @@ -15,8 +15,8 @@ - - + + diff --git a/Analogy.LogServer.Tests/Program.cs b/Analogy.LogServer.Tests/Program.cs index a3daca11..71fbf791 100644 --- a/Analogy.LogServer.Tests/Program.cs +++ b/Analogy.LogServer.Tests/Program.cs @@ -20,4 +20,4 @@ static void Main() Application.Run(new TestForm()); } } -} +} \ No newline at end of file diff --git a/Analogy.LogServer.Tests/TestForm.cs b/Analogy.LogServer.Tests/TestForm.cs index 251539a6..4e2685ba 100644 --- a/Analogy.LogServer.Tests/TestForm.cs +++ b/Analogy.LogServer.Tests/TestForm.cs @@ -37,7 +37,6 @@ private async void btnProducer_Click(object sender, EventArgs e) btnProducer.Enabled = true; } - private async void btnConsumer_Click_1(object sender, EventArgs e) { if (consuming) @@ -58,4 +57,4 @@ private async void btnConsumer_Click_1(object sender, EventArgs e) btnConsumer.Enabled = true; } } -} +} \ No newline at end of file diff --git a/Analogy.LogServer/Analogy.LogServer.csproj b/Analogy.LogServer/Analogy.LogServer.csproj index 7bb7a11b..d775eb13 100644 --- a/Analogy.LogServer/Analogy.LogServer.csproj +++ b/Analogy.LogServer/Analogy.LogServer.csproj @@ -1,7 +1,7 @@ - net7.0-windows + net8.0-windows Exe Analogy.LogServer.Program Lior Banai @@ -19,26 +19,27 @@ snupkg true true - 2.0.3.0 + 3.0.0.0 - Lior Banai @ 2020-2023 + Lior Banai @ 2020-2024 - + - + + - - + + - + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -55,6 +56,13 @@ + + + + + + + all diff --git a/Analogy.LogServer/Controllers/MessagesController.cs b/Analogy.LogServer/Controllers/MessagesController.cs index 6d544a14..6001061e 100644 --- a/Analogy.LogServer/Controllers/MessagesController.cs +++ b/Analogy.LogServer/Controllers/MessagesController.cs @@ -48,7 +48,7 @@ public ActionResult LogMessageObject(Message msg) MachineName = msg.MachineName, FileName = string.Empty, MethodName = string.Empty, - User = string.Empty + User = string.Empty, }; messageContainer.AddMessage(m); return Ok(); @@ -70,12 +70,10 @@ public ActionResult LogMessage(string msg, string level) Class = AnalogyGRPCLogClass.General, FileName = string.Empty, MethodName = string.Empty, - User = string.Empty - + User = string.Empty, }; messageContainer.AddMessage(m); return Ok(); } - } -} +} \ No newline at end of file diff --git a/Analogy.LogServer/GRPCLogConsumer.cs b/Analogy.LogServer/GRPCLogConsumer.cs index 9eb39299..294a7064 100644 --- a/Analogy.LogServer/GRPCLogConsumer.cs +++ b/Analogy.LogServer/GRPCLogConsumer.cs @@ -22,7 +22,7 @@ public GRPCLogConsumer(ILogger logger) { _logger = logger; clients = new List<(IServerStreamWriter stream, bool active)>(); - pendingClients=new List<(IServerStreamWriter stream, bool add)>(); + pendingClients = new List<(IServerStreamWriter stream, bool add)>(); } public void AddGrpcConsumer(string requestMessage, IServerStreamWriter responseStream) @@ -55,7 +55,6 @@ public void RemoveGrpcConsumer(IServerStreamWriter respon public async Task ConsumeLog(AnalogyGRPCLogMessage msg) { - try { await _semaphoreSlim.WaitAsync().ConfigureAwait(false); @@ -92,7 +91,7 @@ public async Task ConsumeLog(AnalogyGRPCLogMessage msg) try { await _semaphoreSlim.WaitAsync().ConfigureAwait(false); - await stream.WriteAsync(msg).ConfigureAwait(false); ; + await stream.WriteAsync(msg).ConfigureAwait(false); } catch (Exception e) { @@ -104,12 +103,8 @@ public async Task ConsumeLog(AnalogyGRPCLogMessage msg) _semaphoreSlim.Release(); } } - - } - - public override string ToString() => $"gRPC consumer"; } -} +} \ No newline at end of file diff --git a/Analogy.LogServer/Interfaces/ILogConsumer.cs b/Analogy.LogServer/Interfaces/ILogConsumer.cs index 96cd91c9..58a4d677 100644 --- a/Analogy.LogServer/Interfaces/ILogConsumer.cs +++ b/Analogy.LogServer/Interfaces/ILogConsumer.cs @@ -9,4 +9,4 @@ public interface ILogConsumer { Task ConsumeLog(AnalogyGRPCLogMessage msg); } -} +} \ No newline at end of file diff --git a/Analogy.LogServer/LogFileConsumer.cs b/Analogy.LogServer/LogFileConsumer.cs index 8e327a9e..b08d1060 100644 --- a/Analogy.LogServer/LogFileConsumer.cs +++ b/Analogy.LogServer/LogFileConsumer.cs @@ -17,7 +17,6 @@ public Task ConsumeLog(AnalogyGRPCLogMessage msg) { switch (msg.Level) { - case AnalogyGRPCLogLevel.None: case AnalogyGRPCLogLevel.Trace: logger.LogTrace(msg.Text); @@ -46,4 +45,4 @@ public Task ConsumeLog(AnalogyGRPCLogMessage msg) return Task.CompletedTask; } } -} +} \ No newline at end of file diff --git a/Analogy.LogServer/MessageHistoryContainer.cs b/Analogy.LogServer/MessageHistoryContainer.cs index b0876565..0d501b9d 100644 --- a/Analogy.LogServer/MessageHistoryContainer.cs +++ b/Analogy.LogServer/MessageHistoryContainer.cs @@ -47,7 +47,6 @@ public async Task CleanMessages(int deleteOlderHours) { _semaphoreSlim.Release(); } - } public async Task CleanMessagesByHalf() @@ -61,7 +60,7 @@ public async Task CleanMessagesByHalf() } finally { - _semaphoreSlim.Release(); + _semaphoreSlim.Release(); } } @@ -70,7 +69,7 @@ public async Task> GetOldMessages() try { await _semaphoreSlim.WaitAsync().ConfigureAwait(false); - return _OldMessages.ToList(); + return _OldMessages.ToList(); } finally { @@ -78,4 +77,4 @@ public async Task> GetOldMessages() } } } -} +} \ No newline at end of file diff --git a/Analogy.LogServer/MessagesContainer.cs b/Analogy.LogServer/MessagesContainer.cs index 2b3f1950..97c5bafc 100644 --- a/Analogy.LogServer/MessagesContainer.cs +++ b/Analogy.LogServer/MessagesContainer.cs @@ -1,7 +1,6 @@ -using System; -using Analogy.LogServer.Interfaces; -using Analogy.LogServer.Services; +using Analogy.LogServer.Interfaces; using Microsoft.Extensions.Logging; +using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; @@ -44,7 +43,7 @@ public MessagesContainer(ServiceConfiguration serviceConfiguration, GRPCLogConsu } catch (Exception e) { - _logger.LogError(e,"Error publishing message"); + _logger.LogError(e, "Error publishing message"); } finally { @@ -86,10 +85,9 @@ public void RemoveConsumer(ILogConsumer consumer) } } - public void Stop() { messages.CompleteAdding(); } } -} +} \ No newline at end of file diff --git a/Analogy.LogServer/Program.cs b/Analogy.LogServer/Program.cs index 40dd72de..e8e42589 100644 --- a/Analogy.LogServer/Program.cs +++ b/Analogy.LogServer/Program.cs @@ -45,7 +45,7 @@ public static async Task Main() private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { - Log.Error(e.ExceptionObject as Exception,"Error: {e}",e); + Log.Error(e.ExceptionObject as Exception, "Error: {e}", e); } private static IHostBuilder CreateHostBuilder() => @@ -63,7 +63,7 @@ private static IHostBuilder CreateHostBuilder() => { options.Configure(context.Configuration.GetSection("Kestrel")); }) - + .UseStartup(); }) .ConfigureServices((hostContext, services) => @@ -72,4 +72,4 @@ private static IHostBuilder CreateHostBuilder() => services.AddHostedService(); }).UseWindowsService(); } -} +} \ No newline at end of file diff --git a/Analogy.LogServer/ServiceConfiguration.cs b/Analogy.LogServer/ServiceConfiguration.cs index 06ac5ef2..b126dcc4 100644 --- a/Analogy.LogServer/ServiceConfiguration.cs +++ b/Analogy.LogServer/ServiceConfiguration.cs @@ -1,5 +1,5 @@ -using System.Collections.Generic; -using Analogy.Interfaces; +using Analogy.Interfaces; +using System.Collections.Generic; namespace Analogy.LogServer { @@ -15,13 +15,11 @@ public ServiceConfiguration() } } - public class WindowsEventLogsConfiguration { public bool EnableMonitoring { get; set; } public bool SaveToLogFile { get; set; } public AnalogyLogLevel MinimumLogLevel { get; set; } public List LogsToMonitor { get; set; } - } -} +} \ No newline at end of file diff --git a/Analogy.LogServer/Services/CleanUpWorker.cs b/Analogy.LogServer/Services/CleanUpWorker.cs index 35569e56..7ebbd72c 100644 --- a/Analogy.LogServer/Services/CleanUpWorker.cs +++ b/Analogy.LogServer/Services/CleanUpWorker.cs @@ -21,7 +21,6 @@ public CleanUpWorker(MessagesContainer messageContainer, MessageHistoryContainer ServiceConfiguration = configuration; MessageContainer = messageContainer; HistoryContainer = historyContainer; - } protected override async Task ExecuteAsync(CancellationToken stoppingToken) @@ -37,7 +36,6 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) await HistoryContainer.CleanMessagesByHalf(); GC.Collect(); } - } catch (TaskCanceledException) { @@ -52,4 +50,4 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) } } } -} +} \ No newline at end of file diff --git a/Analogy.LogServer/Services/GreeterService.cs b/Analogy.LogServer/Services/GreeterService.cs index 362107be..f99d8235 100644 --- a/Analogy.LogServer/Services/GreeterService.cs +++ b/Analogy.LogServer/Services/GreeterService.cs @@ -13,7 +13,6 @@ namespace Analogy.LogServer.Services { public class GreeterService : Analogy.AnalogyBase { - private readonly GRPCLogConsumer _grpcLogConsumer; private ILogger Logger { get; } private MessagesContainer MessageContainer { get; } @@ -31,7 +30,7 @@ public override async Task SubscribeForPublishingMessages(I ? string.Join(",", context.RequestHeaders.Select(h => h.Value).ToArray()) : string.Empty; Logger.LogInformation($"Client subscribe for sending messages. request info :{connectionInfo}"); - var tasks = Task.WhenAll(AwaitCancellation(context.CancellationToken), HandleClientPublisingMessages(requestStream,context, context.CancellationToken)); + var tasks = Task.WhenAll(AwaitCancellation(context.CancellationToken), HandleClientPublisingMessages(requestStream, context, context.CancellationToken)); Logger.LogWarning($"Client subscribe ended for: {connectionInfo}"); try { @@ -52,7 +51,7 @@ await responseStream.WriteAsync(new AnalogyGRPCLogMessage { Category = "Server Message", Text = "Connection Established. Streaming old messages (if Any)", - Level =AnalogyGRPCLogLevel.Analogy, + Level = AnalogyGRPCLogLevel.Analogy, Date = Timestamp.FromDateTime(DateTime.UtcNow), FileName = "", Id = Guid.NewGuid().ToString(), @@ -62,10 +61,9 @@ await responseStream.WriteAsync(new AnalogyGRPCLogMessage ProcessId = Process.GetCurrentProcess().Id, Source = "Server Operations", ThreadId = Thread.CurrentThread.ManagedThreadId, - User = Environment.UserName - + User = Environment.UserName, }); - var oldMessages =await MessageHistoryContainer.GetOldMessages().ConfigureAwait(false); + var oldMessages = await MessageHistoryContainer.GetOldMessages().ConfigureAwait(false); if (oldMessages.Any()) { await responseStream.WriteAllAsync(oldMessages); @@ -114,7 +112,6 @@ private async Task HandleClientPublisingMessages(IAsyncStreamReader(); token.Register(() => { completion.SetResult(null); }); return completion.Task; - } } -} - +} \ No newline at end of file diff --git a/Analogy.LogServer/Services/WindowsEventLogsMonitor.cs b/Analogy.LogServer/Services/WindowsEventLogsMonitor.cs index e8956f53..5690e447 100644 --- a/Analogy.LogServer/Services/WindowsEventLogsMonitor.cs +++ b/Analogy.LogServer/Services/WindowsEventLogsMonitor.cs @@ -37,7 +37,7 @@ protected override Task ExecuteAsync(CancellationToken stoppingToken) catch (Exception e) { string m = "Error Opening log. Please make sure you are running as Administrator." + Environment.NewLine + "Error:" + e.Message; - AnalogyGRPCLogMessage err = new AnalogyGRPCLogMessage { Level = AnalogyGRPCLogLevel.Error, Text = m, Date = Timestamp.FromDateTime(DateTime.UtcNow) ,Id = Guid.NewGuid().ToString()}; + AnalogyGRPCLogMessage err = new AnalogyGRPCLogMessage { Level = AnalogyGRPCLogLevel.Error, Text = m, Date = Timestamp.FromDateTime(DateTime.UtcNow), Id = Guid.NewGuid().ToString() }; MessageContainer.AddMessage(err); } } @@ -60,6 +60,7 @@ private void SetupLogs() { var eventLog = new EventLog(logName); Logs.Add(eventLog); + // set event handler eventLog.EntryWritten += (apps, arg) => { @@ -69,7 +70,6 @@ private void SetupLogs() m.Module = logName; MessageContainer.AddMessage(m); } - }; eventLog.EnableRaisingEvents = true; @@ -80,9 +80,10 @@ private void SetupLogs() string m = "Error Opening log. Please make sure you are running as Administrator." + Environment.NewLine + "Error:" + e.Message; AnalogyGRPCLogMessage err = new AnalogyGRPCLogMessage { - Level = AnalogyGRPCLogLevel.Error, Text = m, + Level = AnalogyGRPCLogLevel.Error, + Text = m, Date = Timestamp.FromDateTime(DateTime.UtcNow), - Id = Guid.NewGuid().ToString() + Id = Guid.NewGuid().ToString(), }; MessageContainer.AddMessage(err); } @@ -160,6 +161,5 @@ private static AnalogyGRPCLogMessage CreateGRPCMessageFromEvent(EventLogEntry eE m.Module = eEntry.Source ?? ""; return m; } - } -} +} \ No newline at end of file diff --git a/Analogy.LogServer/Startup.cs b/Analogy.LogServer/Startup.cs index 9def86aa..912bd008 100644 --- a/Analogy.LogServer/Startup.cs +++ b/Analogy.LogServer/Startup.cs @@ -3,13 +3,13 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using Newtonsoft.Json.Serialization; using Serilog; using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Newtonsoft.Json.Serialization; namespace Analogy.LogServer { @@ -67,4 +67,4 @@ private async Task OnShutdown() await GrpcEnvironment.KillServersAsync(); } } -} +} \ No newline at end of file diff --git a/Analogy.LogServer/Utils.cs b/Analogy.LogServer/Utils.cs index c73c78c4..71dc3682 100644 --- a/Analogy.LogServer/Utils.cs +++ b/Analogy.LogServer/Utils.cs @@ -1,10 +1,10 @@ -using System; +using Analogy.Interfaces; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Runtime.CompilerServices; using System.Threading.Tasks; -using Analogy.Interfaces; namespace Analogy.LogServer { @@ -70,4 +70,4 @@ public static AnalogyGRPCLogLevel GetLogLevelFromString(string level) } } } -} +} \ No newline at end of file diff --git a/BannedSymbols.txt b/BannedSymbols.txt new file mode 100644 index 00000000..26002bbb --- /dev/null +++ b/BannedSymbols.txt @@ -0,0 +1,9 @@ +#https://github.com/dotnet/csharplang/blob/main/spec/documentation-comments.md#id-string-format + +M:System.String.ToLower;Use ToLowerInvariant instead +M:System.String.ToUpper;Use ToUpperInvariant instead + +F:System.StringComparison.CurrentCulture;Consider using Ordinal +F:System.StringComparison.CurrentCultureIgnoreCase;Consider using OrdinalIgnoreCase +F:System.StringComparison.InvariantCurrent;Consider using Ordinal +F:System.StringComparison.InvariantCurrentIgnoreCase;Consider using OrdinalIgnoreCase diff --git a/Directory.Build.props b/Directory.Build.props new file mode 100644 index 00000000..cee7053c --- /dev/null +++ b/Directory.Build.props @@ -0,0 +1,64 @@ + + + true + true + True + snupkg + true + true + true + MIT + true + False + git + portable + + + enable + latest + + + $(DefineContants);DEBUG + false + + + true + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + \ No newline at end of file