Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Trace/LogTrace and Critical/LogCritical #107

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Microsoft.Extensions.Logging;
using System;
using Microsoft.Extensions.Logging;

namespace Arc4u.Diagnostics
{
Expand Down Expand Up @@ -56,11 +56,24 @@ public void LogWarning(string message, params object[] args)
buildMessage.Log();
}

public CommonLoggerProperties Critical(string message, params object[] args)
{
return AddEntry(LogLevel.Critical, message, null, args);
}

public void LogCritical(string message, params object[] args)
{
var buildMessage = AddEntry(LogLevel.Critical, message, null, args);
buildMessage.Log();
}

[Obsolete("This method is obsolete. Use Critical() instead")]
public CommonLoggerProperties Fatal(string message, params object[] args)
{
return AddEntry(LogLevel.Critical, message, null, args);
}

[Obsolete("This method is obsolete. Use LogCritical() instead")]
public void LogFatal(string message, params object[] args)
{
var buildMessage = AddEntry(LogLevel.Critical, message, null, args);
Expand Down Expand Up @@ -89,9 +102,22 @@ public void LogException(Exception exception)
Exception(exception).Log();
}

internal CommonLoggerProperties System(string message, params object[] args)
internal CommonLoggerProperties Trace(string message, params object[] args)
{
return AddEntry(LogLevel.Trace, message, null, args);
}

internal void LogTrace(string message, params object[] args)
{
var buildMessage = AddEntry(LogLevel.Trace, message, null, args);
buildMessage.Log();
}

internal CommonLoggerProperties System(string message, params object[] args)
{
var buildMessage = AddEntry(LogLevel.Trace, message, null, args);
buildMessage.Add("Arc4u", "Internal"); // to disambiguate between system logging inside Arc4u and user logging.
return buildMessage;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Microsoft.Extensions.Logging;
using System;
using Microsoft.Extensions.Logging;

namespace Arc4u.Diagnostics
{
Expand Down Expand Up @@ -35,6 +35,11 @@ public MonitoringLoggerProperties Information(string message)
return AddEntry(LogLevel.Information, message);
}

public MonitoringLoggerProperties Trace(string message)
{
return AddEntry(LogLevel.Trace, message);
}

internal MonitoringLoggerProperties System(string message)
{
return AddEntry(LogLevel.Trace, message);
Expand Down
19 changes: 10 additions & 9 deletions src/Arc4u.Standard.NServiceBus/Diagnostics/LoggerBridge.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Arc4u.Diagnostics;
using NServiceBus.Logging;
using System;
using System.Globalization;
using Arc4u.Diagnostics;
using NServiceBus.Logging;
using LogLevel = Microsoft.Extensions.Logging.LogLevel;

namespace Arc4u.NServiceBus.Diagnostics
Expand Down Expand Up @@ -30,7 +31,7 @@ public void Debug(string message, Exception exception)

public void DebugFormat(string format, params object[] args)
{
LoggerBase.Technical.From<LoggerBridge>().Debug(String.Format(format, args)).Log();
LoggerBase.Technical.From<LoggerBridge>().Debug(String.Format(CultureInfo.InvariantCulture, format, args)).Log();
}

public void Error(string message)
Expand All @@ -46,23 +47,23 @@ public void Error(string message, Exception exception)

public void ErrorFormat(string format, params object[] args)
{
LoggerBase.Technical.From<LoggerBridge>().Error(String.Format(format, args)).Log();
LoggerBase.Technical.From<LoggerBridge>().Error(String.Format(CultureInfo.InvariantCulture, format, args)).Log();
}

public void Fatal(string message)
{
LoggerBase.Technical.From<LoggerBridge>().Fatal(message).Log();
LoggerBase.Technical.From<LoggerBridge>().Critical(message).Log();
}

public void Fatal(string message, Exception exception)
{
LoggerBase.Technical.From<LoggerBridge>().Fatal(message).Log();
LoggerBase.Technical.From<LoggerBridge>().Critical(message).Log();
LoggerBase.Technical.From<LoggerBridge>().Exception(exception).Log();
}

public void FatalFormat(string format, params object[] args)
{
LoggerBase.Technical.From<LoggerBridge>().Fatal(String.Format(format, args)).Log();
LoggerBase.Technical.From<LoggerBridge>().Critical(String.Format(CultureInfo.InvariantCulture, format, args)).Log();
}

public void Info(string message)
Expand All @@ -78,7 +79,7 @@ public void Info(string message, Exception exception)

public void InfoFormat(string format, params object[] args)
{
LoggerBase.Technical.From<LoggerBridge>().Information(String.Format(format, args)).Log();
LoggerBase.Technical.From<LoggerBridge>().Information(String.Format(CultureInfo.InvariantCulture, format, args)).Log();
}

public void Warn(string message)
Expand All @@ -94,7 +95,7 @@ public void Warn(string message, Exception exception)

public void WarnFormat(string format, params object[] args)
{
LoggerBase.Technical.From<LoggerBridge>().Warning(String.Format(format, args)).Log();
LoggerBase.Technical.From<LoggerBridge>().Warning(String.Format(CultureInfo.InvariantCulture, format, args)).Log();
}
}
}
12 changes: 6 additions & 6 deletions src/Arc4u.Standard.UnitTest/Logging/SerilogTests.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Arc4u.Diagnostics;
using Arc4u.Diagnostics.Serilog;
using Arc4u.UnitTest.Infrastructure;
using Microsoft.Extensions.Logging;
using Serilog;
using Serilog.Core;
using Serilog.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Xunit;

namespace Arc4u.UnitTest.Logging;
Expand Down Expand Up @@ -37,7 +37,7 @@ public async Task LoggerArgumentTest()
logger.Technical().LogInformation("Information {Code}", 101);
logger.Technical().LogWarning("Warning {Code}", 102);
logger.Technical().LogError("Error {Code}", 103);
logger.Technical().LogFatal("Fatal {Code}", 104);
logger.Technical().LogCritical("Fatal {Code}", 104);
logger.Technical().LogException(new DivideByZeroException("Cannot divide by zero"));

await Task.Delay(1000);
Expand Down Expand Up @@ -68,7 +68,7 @@ public async Task LoggerTechnicalTest()
logger.Technical().Information("Information").Add("Code", "101").Log();
logger.Technical().Warning("Warning").Add("Code", "102").Log();
logger.Technical().Error("Error").Add("Code", "103").Log();
logger.Technical().Fatal("Fatal").Add("Code", "104").Log();
logger.Technical().Critical("Fatal").Add("Code", "104").Log();
logger.Technical().Exception(new DivideByZeroException("Cannot divide by zero")).Log();
logger.Monitoring().Debug("Memory").AddMemoryUsage().Log();

Expand Down
2 changes: 1 addition & 1 deletion src/Arc4u.Standard/ServiceModel/Messages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void LogAll<T>(ILogger<T> logger, [CallerMemberName] string methodName =
property = categoryLogger.Error(lm.Text);
break;
case MessageType.Critical:
property = categoryLogger.Fatal(lm.Text);
property = categoryLogger.Critical(lm.Text);
break;
default:
property = categoryLogger.Debug(lm.Text);
Expand Down