Added logging for CLI

pull/1089/head
Halil ibrahim Kalkan 7 years ago
parent f5f987189d
commit 37ce88c29e

@ -3,6 +3,7 @@
"TemplateFiles/": {},
"Logs/": {},
"wwwroot/files/": {},
"wwwroot/downloads/": {},
"appsettings.json": {},
"web.config": {}
}

@ -2,9 +2,12 @@
using System.Reflection;
using Microsoft.Extensions.DependencyInjection;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Volo.Abp.Cli.Args;
using Volo.Abp.Cli.Commands;
using Volo.Abp.DependencyInjection;
using Volo.Abp.ProjectBuilding;
namespace Volo.Abp.Cli
{
@ -12,6 +15,8 @@ namespace Volo.Abp.Cli
{
public static string Version => typeof(AbpCliCoreModule).Assembly.GetFileVersion();
public ILogger<CliService> Logger { get; set; }
protected ICommandLineArgumentParser CommandLineArgumentParser { get; }
protected ICommandSelector CommandSelector { get; }
public IHybridServiceScopeFactory ServiceScopeFactory { get; }
@ -24,12 +29,14 @@ namespace Volo.Abp.Cli
CommandLineArgumentParser = commandLineArgumentParser;
CommandSelector = commandSelector;
ServiceScopeFactory = serviceScopeFactory;
Logger = NullLogger<CliService>.Instance;
}
public async Task RunAsync(string[] args)
{
Console.WriteLine("ABP CLI (abp.io)");
Console.WriteLine("Version: " + Version);
Logger.LogInformation("ABP CLI (abp.io)");
Logger.LogInformation("Version: " + Version);
var commandLineArgs = CommandLineArgumentParser.Parse(args);
var commandType = CommandSelector.Select(commandLineArgs);

@ -2,6 +2,8 @@
using System.IO;
using System.Threading.Tasks;
using Ionic.Zip;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Volo.Abp.Cli.Args;
using Volo.Abp.DependencyInjection;
using Volo.Abp.ProjectBuilding;
@ -12,28 +14,32 @@ namespace Volo.Abp.Cli.Commands
{
public class NewProjectCommand : IConsoleCommand, ITransientDependency
{
public ILogger<NewProjectCommand> Logger { get; set; }
protected ProjectBuilder ProjectBuilder { get; }
public NewProjectCommand(ProjectBuilder projectBuilder)
{
ProjectBuilder = projectBuilder;
Logger = NullLogger<NewProjectCommand>.Instance;
}
public async Task ExecuteAsync(CommandLineArgs commandLineArgs)
{
if (commandLineArgs.Target == null)
{
Console.WriteLine("Project name is missing.");
Console.WriteLine("Usage:");
Console.WriteLine(" abp new <project-name> [-t <template-name>]");
Console.WriteLine("Examples:");
Console.WriteLine(" abp new Acme.BookStore");
Console.WriteLine(" abp new Acme.BookStore mvc");
Logger.LogWarning("Project name is missing.");
Logger.LogWarning("Usage:");
Logger.LogWarning(" abp new <project-name> [-t <template-name>]");
Logger.LogWarning("Examples:");
Logger.LogWarning(" abp new Acme.BookStore");
Logger.LogWarning(" abp new Acme.BookStore mvc");
return;
}
Console.WriteLine("Creating a new solution");
Console.WriteLine("Solution name: " + commandLineArgs.Target);
Logger.LogInformation("Creating a new project...");
Logger.LogInformation("Project name: " + commandLineArgs.Target);
var result = await ProjectBuilder.BuildAsync(
new ProjectBuildArgs(

@ -1,16 +1,44 @@
using System.IO;
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Volo.Abp.DependencyInjection;
using Volo.Abp.IO;
namespace Volo.Abp.ProjectBuilding
{
public class AbpIoTemplateStore : ITemplateStore, ITransientDependency
{
public ILogger<AbpIoTemplateStore> Logger { get; set; }
public AbpIoTemplateStore()
{
Logger = NullLogger<AbpIoTemplateStore>.Instance;
}
public async Task<TemplateFile> GetAsync(string templateName, string version)
{
return new TemplateFile(
File.ReadAllBytes("C:\\Temp\\abp-templates\\" + version + "\\" + templateName + ".zip")
);
var localCacheFolder = "C:\\Temp\\abp-template-cache\\" + version;
DirectoryHelper.CreateIfNotExists(localCacheFolder);
var localCacheFile = Path.Combine(localCacheFolder, templateName + ".zip");
if (File.Exists(localCacheFile))
{
Logger.LogInformation("Using cached template: " + templateName + ", version: " + version);
return new TemplateFile(File.ReadAllBytes(localCacheFile));
}
Logger.LogInformation("Downloading template: " + templateName + ", version: " + version);
using (var client = new System.Net.Http.HttpClient())
{
client.Timeout = TimeSpan.FromMinutes(5);
var downloadUrl = "https://abp.io/downloads/templates/" + version + "/" + templateName + ".zip";
var fileContents = await client.GetByteArrayAsync(downloadUrl);
File.WriteAllBytes(localCacheFile, fileContents);
return new TemplateFile(fileContents);
}
}
}
}

@ -12,9 +12,14 @@
<ItemGroup>
<PackageReference Include="NETStandard.Library" Version="2.0.3" />
<PackageReference Include="Serilog.AspNetCore" Version="2.1.1" />
<PackageReference Include="Serilog.Sinks.File" Version="4.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Volo.Abp.Autofac\Volo.Abp.Autofac.csproj" />
<ProjectReference Include="..\Volo.Abp.Cli.Core\Volo.Abp.Cli.Core.csproj" />
</ItemGroup>

@ -1,9 +1,11 @@
using Volo.Abp.Modularity;
using Volo.Abp.Autofac;
using Volo.Abp.Modularity;
namespace Volo.Abp.Cli
{
[DependsOn(
typeof(AbpCliCoreModule)
typeof(AbpCliCoreModule),
typeof(AbpAutofacModule)
)]
public class AbpCliModule : AbpModule
{

@ -1,4 +1,6 @@
using Microsoft.Extensions.DependencyInjection;
using Serilog;
using Serilog.Events;
using Volo.Abp.Threading;
namespace Volo.Abp.Cli
@ -7,7 +9,20 @@ namespace Volo.Abp.Cli
{
private static void Main(string[] args)
{
using (var application = AbpApplicationFactory.Create<AbpCliModule>())
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Information()
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
.Enrich.FromLogContext()
//.WriteTo.File("Logs/logs.txt") //TODO: Write logs to a global path
.WriteTo.Console()
.CreateLogger();
using (var application = AbpApplicationFactory.Create<AbpCliModule>(
options =>
{
options.UseAutofac();
options.Services.AddLogging(c => c.AddSerilog());
}))
{
application.Initialize();

@ -42,12 +42,12 @@ namespace Volo.Abp.Modularity
}
}
_logger.LogInformation("Initialized all modules.");
_logger.LogInformation("Initialized all ABP modules.");
}
private void LogListOfModules()
{
_logger.LogInformation("Loaded modules:");
_logger.LogInformation("Loaded ABP modules:");
foreach (var module in _moduleContainer.Modules)
{

Loading…
Cancel
Save