-
Notifications
You must be signed in to change notification settings - Fork 281
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Switching to programatically defined logger. * Improve BUILD.md to reflect move to .NET Core 2.2
- Loading branch information
Showing
9 changed files
with
97 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,8 +39,5 @@ public static string GetVersionString() | |
return fileVersionInfo.ProductVersion; | ||
|
||
} | ||
|
||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,68 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
using NLog; | ||
using NLog.Config; | ||
using NLog.Targets; | ||
|
||
namespace AttackSurfaceAnalyzer.Utils | ||
{ | ||
public class Logger | ||
{ | ||
|
||
public static ILogger Instance { get; private set; } | ||
|
||
static Logger() | ||
{ | ||
Instance = LogManager.GetCurrentClassLogger(); | ||
} | ||
|
||
public static void Output(string message, params object[] args) | ||
public static void Setup() | ||
{ | ||
Logger.Instance.Info(message, args); | ||
Setup(false, false); | ||
} | ||
|
||
public static void Setup(bool debug, bool verbose) | ||
{ | ||
// Step 1. Create configuration object | ||
var config = new LoggingConfiguration(); | ||
|
||
// Step 2. Create targets | ||
var consoleTarget = new ColoredConsoleTarget("console") | ||
{ | ||
Layout = @"${date:format=HH\:mm\:ss} ${level} ${message} ${exception}" | ||
}; | ||
config.AddTarget(consoleTarget); | ||
|
||
var fileTarget = new FileTarget("debug") | ||
{ | ||
FileName = "asa.debug.log", | ||
Layout = "${longdate} ${level} ${message} ${exception}" | ||
}; | ||
config.AddTarget(fileTarget); | ||
|
||
if (debug) | ||
{ | ||
config.AddRuleForOneLevel(LogLevel.Debug, fileTarget); | ||
config.AddRuleForOneLevel(LogLevel.Warn, consoleTarget); | ||
config.AddRuleForOneLevel(LogLevel.Error, consoleTarget); | ||
config.AddRuleForOneLevel(LogLevel.Fatal, consoleTarget); | ||
} | ||
|
||
if (verbose) | ||
{ | ||
config.AddRuleForAllLevels(consoleTarget); | ||
} | ||
else | ||
{ | ||
config.AddRuleForOneLevel(LogLevel.Info, consoleTarget); | ||
config.AddRuleForOneLevel(LogLevel.Warn, consoleTarget); | ||
config.AddRuleForOneLevel(LogLevel.Error, consoleTarget); | ||
config.AddRuleForOneLevel(LogLevel.Fatal, consoleTarget); | ||
} | ||
|
||
// Step 4. Activate the configuration | ||
LogManager.Configuration = config; | ||
} | ||
|
||
} | ||
} |