-
Notifications
You must be signed in to change notification settings - Fork 0
Get Started
André Secco edited this page Jun 25, 2019
·
5 revisions
To get started, install the package.
Install-Package XLogger.Adapters.Console
dotnet add package XLogger.Adapters.Console
You can use this adapter standalone, but if you are using .NET Core / ASP.NET Core consider using the extensions mentioned here, they make it easier to use XLogger in conjunction with the native Logging API.
The following options are available:
Option | Description | Default Value |
---|---|---|
LogLevel | Specifies the minimum level to log. | Information level (2) |
OnDemand | Defines whether the adapter will work only on demand (true) or will work also integrated with the ASP.NET Core logging pipeline (false). | false |
OutputFormat | Sets the output format of the messages. * The variables availables are: @DateTime, @LogLevel, @Data, @Exception and NewLine. * The NewLine variable is intended for line wrap and can be used multiple times. * Each variable must be contained in curly braces (Example: {@LogLevel} or {NewLine}). * Only the @DateTime variable contains additional format and should be used based on this example: {@DateTime:yyyy-MM-dd HH:mm:ss:fff}. |
{@DateTime} [{@LogLevel}] {@Data} {@Exception} |
The codes below are based on usage in an ASP.NET Core project.
You have two ways to set adapter options:
{
"XLogger": {
"Console": {
"LogLevel": 4,
"OnDemand": false,
"OutputFormat": "{@DateTime:yyyy-MM-dd HH:mm:ss.fff} [{@LogLevel}] {@Data} {@Exception}"
}
}
}
using XLogger;
namespace test
{
public class Program
{
public static void Main(string[] args) =>
CreateWebHostBuilder(args).Build().Run();
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseXLogger(hub => {
hub.AddConsole();
});
}
}
using XLogger;
namespace test
{
public class Program
{
public static void Main(string[] args) =>
CreateWebHostBuilder(args).Build().Run();
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseXLogger(hub => {
hub.AddConsole(config =>
{
config.LogLevel = LogLevel.Error;
config.OnDemand = false;
config.OutputFormat = "{@DateTime:yyyy-MM-dd HH:mm:ss.fff} [{@LogLevel}] {@Data} {@Exception}";
});
});
}
}
To view some ways to write logs in ASP.NET Core, check here.