Added braces
This commit is contained in:
@@ -42,7 +42,10 @@ namespace EonaCat.Logger.EonaCatCoreLogger
|
|||||||
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state,
|
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state,
|
||||||
Exception exception, Func<TState, Exception, string> formatter)
|
Exception exception, Func<TState, Exception, string> formatter)
|
||||||
{
|
{
|
||||||
if (!IsEnabled(logLevel) || formatter == null) return;
|
if (!IsEnabled(logLevel) || formatter == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var message = formatter(state, exception);
|
var message = formatter(state, exception);
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,10 @@ namespace EonaCat.Logger.EonaCatCoreLogger
|
|||||||
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state,
|
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state,
|
||||||
Exception exception, Func<TState, Exception, string> formatter)
|
Exception exception, Func<TState, Exception, string> formatter)
|
||||||
{
|
{
|
||||||
if (!IsEnabled(logLevel) || formatter == null) return;
|
if (!IsEnabled(logLevel) || formatter == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var message = formatter(state, exception);
|
var message = formatter(state, exception);
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,10 @@ namespace EonaCat.Logger.EonaCatCoreLogger
|
|||||||
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state,
|
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state,
|
||||||
Exception exception, Func<TState, Exception, string> formatter)
|
Exception exception, Func<TState, Exception, string> formatter)
|
||||||
{
|
{
|
||||||
if (!IsEnabled(logLevel) || formatter == null) return;
|
if (!IsEnabled(logLevel) || formatter == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var message = formatter(state, exception);
|
var message = formatter(state, exception);
|
||||||
|
|
||||||
|
|||||||
@@ -101,7 +101,11 @@ namespace EonaCat.Logger.EonaCatCoreLogger
|
|||||||
List<string> toSend;
|
List<string> toSend;
|
||||||
lock (_lock)
|
lock (_lock)
|
||||||
{
|
{
|
||||||
if (_buffer.Count == 0) return;
|
if (_buffer.Count == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
toSend = new List<string>(_buffer);
|
toSend = new List<string>(_buffer);
|
||||||
_buffer.Clear();
|
_buffer.Clear();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,10 @@ namespace EonaCat.Logger.EonaCatCoreLogger
|
|||||||
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state,
|
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state,
|
||||||
Exception exception, Func<TState, Exception, string> formatter)
|
Exception exception, Func<TState, Exception, string> formatter)
|
||||||
{
|
{
|
||||||
if (!IsEnabled(logLevel) || formatter == null) return;
|
if (!IsEnabled(logLevel) || formatter == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var message = formatter(state, exception);
|
var message = formatter(state, exception);
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,10 @@ namespace EonaCat.Logger.EonaCatCoreLogger
|
|||||||
|
|
||||||
public async void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
|
public async void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
|
||||||
{
|
{
|
||||||
if (!IsEnabled(logLevel)) return;
|
if (!IsEnabled(logLevel))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var message = $"[{DateTime.UtcNow:u}] [{logLevel}] {_categoryName}: {formatter(state, exception)}";
|
var message = $"[{DateTime.UtcNow:u}] [{logLevel}] {_categoryName}: {formatter(state, exception)}";
|
||||||
if (exception != null)
|
if (exception != null)
|
||||||
|
|||||||
@@ -47,7 +47,9 @@ public class Graylog : IDisposable
|
|||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(value))
|
if (string.IsNullOrEmpty(value))
|
||||||
|
{
|
||||||
throw new ArgumentNullException(nameof(Hostname));
|
throw new ArgumentNullException(nameof(Hostname));
|
||||||
|
}
|
||||||
|
|
||||||
_Hostname = value;
|
_Hostname = value;
|
||||||
SetUdp();
|
SetUdp();
|
||||||
@@ -60,7 +62,9 @@ public class Graylog : IDisposable
|
|||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (value < 0)
|
if (value < 0)
|
||||||
|
{
|
||||||
throw new ArgumentException("Port must be zero or greater.");
|
throw new ArgumentException("Port must be zero or greater.");
|
||||||
|
}
|
||||||
|
|
||||||
_Port = value;
|
_Port = value;
|
||||||
SetUdp();
|
SetUdp();
|
||||||
|
|||||||
@@ -95,7 +95,10 @@ public class Splunk : IDisposable
|
|||||||
|
|
||||||
public async Task<HttpResponseMessage> SendAsync(SplunkPayload splunkPayload, bool disableSplunkSSL = false)
|
public async Task<HttpResponseMessage> SendAsync(SplunkPayload splunkPayload, bool disableSplunkSSL = false)
|
||||||
{
|
{
|
||||||
if (splunkPayload == null) return null;
|
if (splunkPayload == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
var eventObject = new
|
var eventObject = new
|
||||||
{
|
{
|
||||||
@@ -115,7 +118,10 @@ public class Splunk : IDisposable
|
|||||||
}
|
}
|
||||||
|
|
||||||
var eventJson = JsonHelper.ToJson(eventObject);
|
var eventJson = JsonHelper.ToJson(eventObject);
|
||||||
if (!HasHecToken) CreateHttpClient();
|
if (!HasHecToken)
|
||||||
|
{
|
||||||
|
CreateHttpClient();
|
||||||
|
}
|
||||||
|
|
||||||
using var content = new StringContent(eventJson, Encoding.UTF8, "application/json");
|
using var content = new StringContent(eventJson, Encoding.UTF8, "application/json");
|
||||||
return await HttpClient.PostAsync("/services/collector/event", content);
|
return await HttpClient.PostAsync("/services/collector/event", content);
|
||||||
|
|||||||
@@ -47,9 +47,11 @@ public class Syslog : IDisposable
|
|||||||
get => _Hostname;
|
get => _Hostname;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(value))
|
if (string.IsNullOrEmpty(value))
|
||||||
throw new ArgumentNullException(nameof(Hostname));
|
{
|
||||||
|
throw new ArgumentNullException(nameof(Hostname));
|
||||||
|
}
|
||||||
|
|
||||||
_Hostname = value;
|
_Hostname = value;
|
||||||
SetUdp();
|
SetUdp();
|
||||||
}
|
}
|
||||||
@@ -60,9 +62,11 @@ public class Syslog : IDisposable
|
|||||||
get => _Port;
|
get => _Port;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (value < 0)
|
if (value < 0)
|
||||||
throw new ArgumentException("Port must be zero or greater.");
|
{
|
||||||
|
throw new ArgumentException("Port must be zero or greater.");
|
||||||
|
}
|
||||||
|
|
||||||
_Port = value;
|
_Port = value;
|
||||||
SetUdp();
|
SetUdp();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,9 @@ namespace EonaCat.Logger.Servers.Tcp
|
|||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(value))
|
if (string.IsNullOrEmpty(value))
|
||||||
|
{
|
||||||
throw new ArgumentNullException(nameof(Hostname));
|
throw new ArgumentNullException(nameof(Hostname));
|
||||||
|
}
|
||||||
|
|
||||||
_Hostname = value;
|
_Hostname = value;
|
||||||
SetTcp();
|
SetTcp();
|
||||||
@@ -56,7 +58,9 @@ namespace EonaCat.Logger.Servers.Tcp
|
|||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (value < 0)
|
if (value < 0)
|
||||||
|
{
|
||||||
throw new ArgumentException("Port must be zero or greater.");
|
throw new ArgumentException("Port must be zero or greater.");
|
||||||
|
}
|
||||||
|
|
||||||
_Port = value;
|
_Port = value;
|
||||||
SetTcp();
|
SetTcp();
|
||||||
|
|||||||
@@ -42,7 +42,9 @@ namespace EonaCat.Logger.Servers.Udp
|
|||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(value))
|
if (string.IsNullOrEmpty(value))
|
||||||
|
{
|
||||||
throw new ArgumentNullException(nameof(Hostname));
|
throw new ArgumentNullException(nameof(Hostname));
|
||||||
|
}
|
||||||
|
|
||||||
_Hostname = value;
|
_Hostname = value;
|
||||||
SetUdp();
|
SetUdp();
|
||||||
@@ -55,7 +57,9 @@ namespace EonaCat.Logger.Servers.Udp
|
|||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (value < 0)
|
if (value < 0)
|
||||||
|
{
|
||||||
throw new ArgumentException("Port must be zero or greater.");
|
throw new ArgumentException("Port must be zero or greater.");
|
||||||
|
}
|
||||||
|
|
||||||
_Port = value;
|
_Port = value;
|
||||||
SetUdp();
|
SetUdp();
|
||||||
|
|||||||
@@ -464,4 +464,4 @@ jsonLogger?.SetContext("UserId", "john.doe");
|
|||||||
jsonLogger?.LogInformation("User logged in");
|
jsonLogger?.LogInformation("User logged in");
|
||||||
````
|
````
|
||||||
// Output:
|
// 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
|
||||||
|
|||||||
@@ -271,14 +271,13 @@ async Task RunWebLoggerTestsAsync()
|
|||||||
i++;
|
i++;
|
||||||
await Task.Run(async () =>
|
await Task.Run(async () =>
|
||||||
{
|
{
|
||||||
await logger.LogAsync($"test via logger {i} INFO").ConfigureAwait(false);
|
await logger.LogAsync($"test via logger {i}").ConfigureAwait(false);
|
||||||
await logger.LogAsync($"test via logger {i} CRITICAL", ELogType.CRITICAL).ConfigureAwait(false);
|
await logger.LogAsync($"test via logger {i}", ELogType.CRITICAL).ConfigureAwait(false);
|
||||||
await logger.LogAsync($"test via logger {i} DEBUG", ELogType.DEBUG).ConfigureAwait(false);
|
await logger.LogAsync($"test via logger {i}", ELogType.DEBUG).ConfigureAwait(false);
|
||||||
await logger.LogAsync($"test via logger {i} ERROR", ELogType.ERROR).ConfigureAwait(false);
|
await logger.LogAsync($"test via logger {i}", ELogType.ERROR).ConfigureAwait(false);
|
||||||
await logger.LogAsync($"test via logger {i} TRACE", ELogType.TRACE).ConfigureAwait(false);
|
await logger.LogAsync($"test via logger {i}", ELogType.TRAFFIC).ConfigureAwait(false);
|
||||||
await logger.LogAsync($"test via logger {i} TRAFFIC", ELogType.TRAFFIC).ConfigureAwait(false);
|
await logger.LogAsync($"test via logger {i}", ELogType.WARNING).ConfigureAwait(false);
|
||||||
await logger.LogAsync($"test via logger {i} WARNING", ELogType.WARNING).ConfigureAwait(false);
|
await logger.LogAsync($"test via logger {i}", ELogType.NONE).ConfigureAwait(false);
|
||||||
await logger.LogAsync($"test via logger {i} NONE", ELogType.NONE).ConfigureAwait(false);
|
|
||||||
}).ConfigureAwait(false);
|
}).ConfigureAwait(false);
|
||||||
await Task.Delay(1).ConfigureAwait(false);
|
await Task.Delay(1).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user