From d981397b027c078864bd12b1fa2ed93526816172 Mon Sep 17 00:00:00 2001 From: EonaCat Date: Sun, 27 Apr 2025 08:07:47 +0200 Subject: [PATCH] Added braces --- .../EonaCatCoreLogger/BatchingDatabaseLogger.cs | 5 ++++- .../EonaCatCoreLogger/DatabaseLogger.cs | 5 ++++- .../EonaCatCoreLogger/DiscordLogger.cs | 5 ++++- .../EonaCatCoreLogger/ElasticSearchLogger.cs | 6 +++++- EonaCat.Logger/EonaCatCoreLogger/SlackLogger.cs | 5 ++++- .../EonaCatCoreLogger/TelegramLogger.cs | 5 ++++- EonaCat.Logger/Servers/GrayLog/Graylog.cs | 4 ++++ EonaCat.Logger/Servers/Splunk/Splunk.cs | 10 ++++++++-- EonaCat.Logger/Servers/Syslog/Syslog.cs | 16 ++++++++++------ EonaCat.Logger/Servers/Tcp/Tcp.cs | 4 ++++ EonaCat.Logger/Servers/Udp/Udp.cs | 4 ++++ README.md | 2 +- Testers/EonaCat.Logger.Test.Web/Program.cs | 15 +++++++-------- 13 files changed, 63 insertions(+), 23 deletions(-) diff --git a/EonaCat.Logger/EonaCatCoreLogger/BatchingDatabaseLogger.cs b/EonaCat.Logger/EonaCatCoreLogger/BatchingDatabaseLogger.cs index e3477e4..de276e4 100644 --- a/EonaCat.Logger/EonaCatCoreLogger/BatchingDatabaseLogger.cs +++ b/EonaCat.Logger/EonaCatCoreLogger/BatchingDatabaseLogger.cs @@ -42,7 +42,10 @@ namespace EonaCat.Logger.EonaCatCoreLogger public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) { - if (!IsEnabled(logLevel) || formatter == null) return; + if (!IsEnabled(logLevel) || formatter == null) + { + return; + } var message = formatter(state, exception); diff --git a/EonaCat.Logger/EonaCatCoreLogger/DatabaseLogger.cs b/EonaCat.Logger/EonaCatCoreLogger/DatabaseLogger.cs index 2abf87b..ac2e715 100644 --- a/EonaCat.Logger/EonaCatCoreLogger/DatabaseLogger.cs +++ b/EonaCat.Logger/EonaCatCoreLogger/DatabaseLogger.cs @@ -32,7 +32,10 @@ namespace EonaCat.Logger.EonaCatCoreLogger public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) { - if (!IsEnabled(logLevel) || formatter == null) return; + if (!IsEnabled(logLevel) || formatter == null) + { + return; + } var message = formatter(state, exception); diff --git a/EonaCat.Logger/EonaCatCoreLogger/DiscordLogger.cs b/EonaCat.Logger/EonaCatCoreLogger/DiscordLogger.cs index 9ad3c1d..f8b2cfb 100644 --- a/EonaCat.Logger/EonaCatCoreLogger/DiscordLogger.cs +++ b/EonaCat.Logger/EonaCatCoreLogger/DiscordLogger.cs @@ -33,7 +33,10 @@ namespace EonaCat.Logger.EonaCatCoreLogger public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) { - if (!IsEnabled(logLevel) || formatter == null) return; + if (!IsEnabled(logLevel) || formatter == null) + { + return; + } var message = formatter(state, exception); diff --git a/EonaCat.Logger/EonaCatCoreLogger/ElasticSearchLogger.cs b/EonaCat.Logger/EonaCatCoreLogger/ElasticSearchLogger.cs index 5ba6d1b..718eed7 100644 --- a/EonaCat.Logger/EonaCatCoreLogger/ElasticSearchLogger.cs +++ b/EonaCat.Logger/EonaCatCoreLogger/ElasticSearchLogger.cs @@ -101,7 +101,11 @@ namespace EonaCat.Logger.EonaCatCoreLogger List toSend; lock (_lock) { - if (_buffer.Count == 0) return; + if (_buffer.Count == 0) + { + return; + } + toSend = new List(_buffer); _buffer.Clear(); } diff --git a/EonaCat.Logger/EonaCatCoreLogger/SlackLogger.cs b/EonaCat.Logger/EonaCatCoreLogger/SlackLogger.cs index cfb1d36..23e7b62 100644 --- a/EonaCat.Logger/EonaCatCoreLogger/SlackLogger.cs +++ b/EonaCat.Logger/EonaCatCoreLogger/SlackLogger.cs @@ -36,7 +36,10 @@ namespace EonaCat.Logger.EonaCatCoreLogger public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) { - if (!IsEnabled(logLevel) || formatter == null) return; + if (!IsEnabled(logLevel) || formatter == null) + { + return; + } var message = formatter(state, exception); diff --git a/EonaCat.Logger/EonaCatCoreLogger/TelegramLogger.cs b/EonaCat.Logger/EonaCatCoreLogger/TelegramLogger.cs index eb50a3b..f404025 100644 --- a/EonaCat.Logger/EonaCatCoreLogger/TelegramLogger.cs +++ b/EonaCat.Logger/EonaCatCoreLogger/TelegramLogger.cs @@ -27,7 +27,10 @@ namespace EonaCat.Logger.EonaCatCoreLogger public async void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) { - if (!IsEnabled(logLevel)) return; + if (!IsEnabled(logLevel)) + { + return; + } var message = $"[{DateTime.UtcNow:u}] [{logLevel}] {_categoryName}: {formatter(state, exception)}"; if (exception != null) diff --git a/EonaCat.Logger/Servers/GrayLog/Graylog.cs b/EonaCat.Logger/Servers/GrayLog/Graylog.cs index bba57e7..39b5b76 100644 --- a/EonaCat.Logger/Servers/GrayLog/Graylog.cs +++ b/EonaCat.Logger/Servers/GrayLog/Graylog.cs @@ -47,7 +47,9 @@ public class Graylog : IDisposable set { if (string.IsNullOrEmpty(value)) + { throw new ArgumentNullException(nameof(Hostname)); + } _Hostname = value; SetUdp(); @@ -60,7 +62,9 @@ public class Graylog : IDisposable set { if (value < 0) + { throw new ArgumentException("Port must be zero or greater."); + } _Port = value; SetUdp(); diff --git a/EonaCat.Logger/Servers/Splunk/Splunk.cs b/EonaCat.Logger/Servers/Splunk/Splunk.cs index 31bfdb8..8e332d4 100644 --- a/EonaCat.Logger/Servers/Splunk/Splunk.cs +++ b/EonaCat.Logger/Servers/Splunk/Splunk.cs @@ -95,7 +95,10 @@ public class Splunk : IDisposable public async Task SendAsync(SplunkPayload splunkPayload, bool disableSplunkSSL = false) { - if (splunkPayload == null) return null; + if (splunkPayload == null) + { + return null; + } var eventObject = new { @@ -115,7 +118,10 @@ public class Splunk : IDisposable } var eventJson = JsonHelper.ToJson(eventObject); - if (!HasHecToken) CreateHttpClient(); + if (!HasHecToken) + { + CreateHttpClient(); + } using var content = new StringContent(eventJson, Encoding.UTF8, "application/json"); return await HttpClient.PostAsync("/services/collector/event", content); diff --git a/EonaCat.Logger/Servers/Syslog/Syslog.cs b/EonaCat.Logger/Servers/Syslog/Syslog.cs index e7f24fb..e896071 100644 --- a/EonaCat.Logger/Servers/Syslog/Syslog.cs +++ b/EonaCat.Logger/Servers/Syslog/Syslog.cs @@ -47,9 +47,11 @@ public class Syslog : IDisposable get => _Hostname; set { - if (string.IsNullOrEmpty(value)) - throw new ArgumentNullException(nameof(Hostname)); - + if (string.IsNullOrEmpty(value)) + { + throw new ArgumentNullException(nameof(Hostname)); + } + _Hostname = value; SetUdp(); } @@ -60,9 +62,11 @@ public class Syslog : IDisposable get => _Port; set { - if (value < 0) - throw new ArgumentException("Port must be zero or greater."); - + if (value < 0) + { + throw new ArgumentException("Port must be zero or greater."); + } + _Port = value; SetUdp(); } diff --git a/EonaCat.Logger/Servers/Tcp/Tcp.cs b/EonaCat.Logger/Servers/Tcp/Tcp.cs index ed1d47e..8c5f59d 100644 --- a/EonaCat.Logger/Servers/Tcp/Tcp.cs +++ b/EonaCat.Logger/Servers/Tcp/Tcp.cs @@ -43,7 +43,9 @@ namespace EonaCat.Logger.Servers.Tcp set { if (string.IsNullOrEmpty(value)) + { throw new ArgumentNullException(nameof(Hostname)); + } _Hostname = value; SetTcp(); @@ -56,7 +58,9 @@ namespace EonaCat.Logger.Servers.Tcp set { if (value < 0) + { throw new ArgumentException("Port must be zero or greater."); + } _Port = value; SetTcp(); diff --git a/EonaCat.Logger/Servers/Udp/Udp.cs b/EonaCat.Logger/Servers/Udp/Udp.cs index b0471f4..a5a0ca2 100644 --- a/EonaCat.Logger/Servers/Udp/Udp.cs +++ b/EonaCat.Logger/Servers/Udp/Udp.cs @@ -42,7 +42,9 @@ namespace EonaCat.Logger.Servers.Udp set { if (string.IsNullOrEmpty(value)) + { throw new ArgumentNullException(nameof(Hostname)); + } _Hostname = value; SetUdp(); @@ -55,7 +57,9 @@ namespace EonaCat.Logger.Servers.Udp set { if (value < 0) + { throw new ArgumentException("Port must be zero or greater."); + } _Port = value; SetUdp(); diff --git a/README.md b/README.md index 65b5fd4..4f82ddd 100644 --- a/README.md +++ b/README.md @@ -464,4 +464,4 @@ jsonLogger?.SetContext("UserId", "john.doe"); jsonLogger?.LogInformation("User logged in"); ```` // Output: -// [2025-04-25 17:01:00Z] [Information] MyCategory: User logged in | CorrelationId=abc-123 UserId=john.doe +// [2025-04-25 17:01:00Z] [Information] MyCategory: User logged in CorrelationId=abc-123 UserId=john.doe diff --git a/Testers/EonaCat.Logger.Test.Web/Program.cs b/Testers/EonaCat.Logger.Test.Web/Program.cs index 78a062f..90c9764 100644 --- a/Testers/EonaCat.Logger.Test.Web/Program.cs +++ b/Testers/EonaCat.Logger.Test.Web/Program.cs @@ -271,14 +271,13 @@ async Task RunWebLoggerTestsAsync() i++; await Task.Run(async () => { - await logger.LogAsync($"test via logger {i} INFO").ConfigureAwait(false); - await logger.LogAsync($"test via logger {i} CRITICAL", ELogType.CRITICAL).ConfigureAwait(false); - await logger.LogAsync($"test via logger {i} DEBUG", ELogType.DEBUG).ConfigureAwait(false); - await logger.LogAsync($"test via logger {i} ERROR", ELogType.ERROR).ConfigureAwait(false); - await logger.LogAsync($"test via logger {i} TRACE", ELogType.TRACE).ConfigureAwait(false); - await logger.LogAsync($"test via logger {i} TRAFFIC", ELogType.TRAFFIC).ConfigureAwait(false); - await logger.LogAsync($"test via logger {i} WARNING", ELogType.WARNING).ConfigureAwait(false); - await logger.LogAsync($"test via logger {i} NONE", ELogType.NONE).ConfigureAwait(false); + await logger.LogAsync($"test via logger {i}").ConfigureAwait(false); + await logger.LogAsync($"test via logger {i}", ELogType.CRITICAL).ConfigureAwait(false); + await logger.LogAsync($"test via logger {i}", ELogType.DEBUG).ConfigureAwait(false); + await logger.LogAsync($"test via logger {i}", ELogType.ERROR).ConfigureAwait(false); + await logger.LogAsync($"test via logger {i}", ELogType.TRAFFIC).ConfigureAwait(false); + await logger.LogAsync($"test via logger {i}", ELogType.WARNING).ConfigureAwait(false); + await logger.LogAsync($"test via logger {i}", ELogType.NONE).ConfigureAwait(false); }).ConfigureAwait(false); await Task.Delay(1).ConfigureAwait(false); }