Browse Source

Override Volo.Abp log level and enhance logging.

pull/1120/head
Halil ibrahim Kalkan 7 years ago
parent
commit
ae68ae6465
  1. 23
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/HelpCommand.cs
  2. 4
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/LoginCommand.cs
  3. 1
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs
  4. 3
      framework/src/Volo.Abp.Cli/Volo.Abp.Cli.csproj
  5. 2
      framework/src/Volo.Abp.Cli/Volo/Abp/Cli/Program.cs

23
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/HelpCommand.cs

@ -1,5 +1,6 @@
using System; using System.Threading.Tasks;
using System.Threading.Tasks; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Volo.Abp.Cli.Args; using Volo.Abp.Cli.Args;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
@ -7,13 +8,21 @@ namespace Volo.Abp.Cli.Commands
{ {
public class HelpCommand : IConsoleCommand, ITransientDependency public class HelpCommand : IConsoleCommand, ITransientDependency
{ {
public ILogger<HelpCommand> Logger { get; set; }
public HelpCommand()
{
Logger = NullLogger<HelpCommand>.Instance;
}
public Task ExecuteAsync(CommandLineArgs commandLineArgs) public Task ExecuteAsync(CommandLineArgs commandLineArgs)
{ {
Console.WriteLine(); Logger.LogInformation("");
Console.WriteLine("Usage:"); Logger.LogInformation("Usage:");
Console.WriteLine(); Logger.LogInformation("");
Console.WriteLine(" abp <command> <target> [options]"); Logger.LogInformation(" abp <command> <target> [options]");
Console.WriteLine(); Logger.LogInformation("");
return Task.CompletedTask; return Task.CompletedTask;
} }
} }

4
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/LoginCommand.cs

@ -25,6 +25,7 @@ namespace Volo.Abp.Cli.Commands
{ {
if (commandLineArgs.Target.IsNullOrEmpty()) if (commandLineArgs.Target.IsNullOrEmpty())
{ {
Logger.LogInformation("");
Logger.LogWarning("Username is missing."); Logger.LogWarning("Username is missing.");
LogHelp(); LogHelp();
return; return;
@ -34,6 +35,7 @@ namespace Volo.Abp.Cli.Commands
var password = ConsoleHelper.ReadSecret(); var password = ConsoleHelper.ReadSecret();
if (password.IsNullOrWhiteSpace()) if (password.IsNullOrWhiteSpace())
{ {
Logger.LogInformation("");
Logger.LogWarning("Password is missing."); Logger.LogWarning("Password is missing.");
LogHelp(); LogHelp();
return; return;
@ -41,7 +43,7 @@ namespace Volo.Abp.Cli.Commands
await AuthService.LoginAsync(commandLineArgs.Target, password); await AuthService.LoginAsync(commandLineArgs.Target, password);
Console.WriteLine($"Successfully logged in as '{commandLineArgs.Target}'"); Logger.LogInformation($"Successfully logged in as '{commandLineArgs.Target}'");
} }
private void LogHelp() private void LogHelp()

1
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs

@ -27,6 +27,7 @@ namespace Volo.Abp.Cli.Commands
{ {
if (commandLineArgs.Target == null) if (commandLineArgs.Target == null)
{ {
Logger.LogInformation("");
Logger.LogWarning("Project name is missing."); Logger.LogWarning("Project name is missing.");
Logger.LogWarning(""); Logger.LogWarning("");
Logger.LogWarning("Usage:"); Logger.LogWarning("Usage:");

3
framework/src/Volo.Abp.Cli/Volo.Abp.Cli.csproj

@ -12,10 +12,9 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="NETStandard.Library" Version="2.0.3" /> <PackageReference Include="NETStandard.Library" Version="2.0.3" />
<PackageReference Include="Serilog.AspNetCore" Version="2.1.1" /> <PackageReference Include="Serilog.Extensions.Logging" Version="2.0.4" />
<PackageReference Include="Serilog.Sinks.File" Version="4.0.0" /> <PackageReference Include="Serilog.Sinks.File" Version="4.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" /> <PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

2
framework/src/Volo.Abp.Cli/Volo/Abp/Cli/Program.cs

@ -13,6 +13,8 @@ namespace Volo.Abp.Cli
Log.Logger = new LoggerConfiguration() Log.Logger = new LoggerConfiguration()
.MinimumLevel.Information() .MinimumLevel.Information()
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning) .MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
.MinimumLevel.Override("Volo.Abp", LogEventLevel.Warning)
.MinimumLevel.Override("Volo.Abp.Cli", LogEventLevel.Information)
.Enrich.FromLogContext() .Enrich.FromLogContext()
.WriteTo.File(Path.Combine(CliPaths.Log, "abp-cli-logs.txt")) .WriteTo.File(Path.Combine(CliPaths.Log, "abp-cli-logs.txt"))
.WriteTo.Console() .WriteTo.Console()

Loading…
Cancel
Save