Skip to content

Commit 9834472

Browse files
authored
Added more metadata to console logging if not a console app (#1319)
* Added more metadata to console logging if not a console app * Logs with [] around timestamp
1 parent 018dd93 commit 9834472

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

NitroxModel/Logger/Log.cs

+7-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static string PlayerName
2323
set => SetPlayerName(value);
2424
}
2525

26-
public static void Setup(bool asyncConsoleWriter = false, InGameLogger inGameLogger = null)
26+
public static void Setup(bool asyncConsoleWriter = false, InGameLogger inGameLogger = null, bool isConsoleApp = false)
2727
{
2828
if (logger != null)
2929
{
@@ -33,7 +33,12 @@ public static void Setup(bool asyncConsoleWriter = false, InGameLogger inGameLog
3333
.MinimumLevel.Debug()
3434
.WriteTo.Logger(cnf =>
3535
{
36-
string consoleTemplate = "{Timestamp:HH:mm:ss.fff} {Message}{NewLine}{Exception}";
36+
string consoleTemplate = isConsoleApp switch
37+
{
38+
false => $"[{{Timestamp:HH:mm:ss.fff}}] [{GetLoggerName()}{{{nameof(PlayerName)}}}][{{Level:u3}}] {{Message}}{{NewLine}}{{Exception}}",
39+
_ => "[{Timestamp:HH:mm:ss.fff}] {Message}{NewLine}{Exception}"
40+
};
41+
3742
if (asyncConsoleWriter)
3843
{
3944
cnf.WriteTo.Async(a => a.ColoredConsole(outputTemplate: consoleTemplate));

NitroxServer-Subnautica/Program.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class Program
3232
private static async Task Main(string[] args)
3333
{
3434
// The thread that writers to console is paused while selecting text in console. So console writer needs to be async.
35-
Log.Setup(asyncConsoleWriter: true);
35+
Log.Setup(asyncConsoleWriter: true, isConsoleApp: true);
3636
AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException;
3737

3838
ConfigureCultureInfo();

0 commit comments

Comments
 (0)