Skip to content

Commit

Permalink
Added more metadata to console logging if not a console app (#1319)
Browse files Browse the repository at this point in the history
* Added more metadata to console logging if not a console app

* Logs with [] around timestamp
  • Loading branch information
Measurity authored Dec 13, 2020
1 parent 018dd93 commit 9834472
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions NitroxModel/Logger/Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static string PlayerName
set => SetPlayerName(value);
}

public static void Setup(bool asyncConsoleWriter = false, InGameLogger inGameLogger = null)
public static void Setup(bool asyncConsoleWriter = false, InGameLogger inGameLogger = null, bool isConsoleApp = false)
{
if (logger != null)
{
Expand All @@ -33,7 +33,12 @@ public static void Setup(bool asyncConsoleWriter = false, InGameLogger inGameLog
.MinimumLevel.Debug()
.WriteTo.Logger(cnf =>
{
string consoleTemplate = "{Timestamp:HH:mm:ss.fff} {Message}{NewLine}{Exception}";
string consoleTemplate = isConsoleApp switch
{
false => $"[{{Timestamp:HH:mm:ss.fff}}] [{GetLoggerName()}{{{nameof(PlayerName)}}}][{{Level:u3}}] {{Message}}{{NewLine}}{{Exception}}",
_ => "[{Timestamp:HH:mm:ss.fff}] {Message}{NewLine}{Exception}"
};

if (asyncConsoleWriter)
{
cnf.WriteTo.Async(a => a.ColoredConsole(outputTemplate: consoleTemplate));
Expand Down
2 changes: 1 addition & 1 deletion NitroxServer-Subnautica/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class Program
private static async Task Main(string[] args)
{
// The thread that writers to console is paused while selecting text in console. So console writer needs to be async.
Log.Setup(asyncConsoleWriter: true);
Log.Setup(asyncConsoleWriter: true, isConsoleApp: true);
AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException;

ConfigureCultureInfo();
Expand Down

0 comments on commit 9834472

Please sign in to comment.