Skip to content

.NET Core Console Application

Chad Ramos edited this page Mar 24, 2019 · 12 revisions

Configuration

Add a appsettings.json file to your project and ensure it is set its "Copy to Output Directory" property to "Copy if newer".

{
  "PioneerLogsConfiguration": {
    "ApplicationName": "Pioneer Logs",
    "ApplicationLayer": "Samples.AspNetCore",
    "Errors": {
      "WriteToFile": false,
      "WriteToConsole": true
    },
    "Usage": {
      "WriteToFile": false,
      "WriteToConsole": true
    },
    "Performance": {
      "WriteToFile": false,
      "WriteToConsole": true
    },
    "Diagnostics": {
      "WriteToFile": true,
      "WriteToConsole": true
    }
  }
}

forceWriteToFile

Default write targets are demonstrated above. You can override both console and file globally, per log category. If you need to overwrite on a log to log context, you can provide the forceWriteToFile flag to any category.

PioneerLogsTub.LogError("Oh NO!!!", forceWriteToFile: true);

Global Exception Handler

Register the Tub to setup up global exception handling.

private static void Main(string[] args)
{
    _config = PioneerLogsTub.RegisterLogger();
    ....
}

Performance

private static void PerformanceTest()
{
    PioneerLogsTub.StartPerformanceTracker();
    System.Threading.Thread.Sleep(1000);
    PioneerLogsTub.StopPerformanceTracker();
}

Usage

public static void LogUsage(string message, Dictionary<string, object> additionalInfo = null, bool forceWriteToFile = false);

Diagnostic

public static void LogDiagnostic(string message, Dictionary<string, object> additionalInfo = null, bool forceWriteToFile = false);

Error

public static void LogError(Exception ex, bool forceWriteToFile = false);
public static void LogError(string message, bool forceWriteToFile = false);
public static void LogError(Exception ex, string message, bool forceWriteToFile = false);
Clone this wiki locally