diff --git a/docs/en/cli/index.md b/docs/en/cli/index.md index c02391eb42..8196ba993e 100644 --- a/docs/en/cli/index.md +++ b/docs/en/cli/index.md @@ -45,6 +45,7 @@ Here is the list of all available commands before explaining their details: - [new-package](../cli#new-package): Generates a new package based on the given template. - [update](../cli#update): Automatically updates all ABP related NuGet and NPM packages in a solution. - [clean](../cli#clean): Deletes all `BIN` and `OBJ` folders in the current folder. +- [clean-logs](../cli#clean-logs): Delete all `*logs.txt` files in the current folder and its subfolders. - [add-package](../cli#add-package): Adds an ABP package to a project. - [add-package-ref](../cli#add-package-ref): Adds package to given project. - [install-module](../cli#install-module): Adds a [multi-package application module](../modules/index.md) to a given module. @@ -476,6 +477,16 @@ Usage: abp clean ``` +### clean-logs + +Delete all `*logs.txt` files in the current folder and its subfolders. + +Usage: + +```bash +abp clean-logs +``` + ### add-package Adds an ABP package to a project by, diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/AbpCliCoreModule.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/AbpCliCoreModule.cs index b8af22ff19..25f9268ff2 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/AbpCliCoreModule.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/AbpCliCoreModule.cs @@ -75,6 +75,7 @@ public class AbpCliCoreModule : AbpModule options.Commands[CreateMigrationAndRunMigratorCommand.Name] = typeof(CreateMigrationAndRunMigratorCommand); options.Commands[InstallLibsCommand.Name] = typeof(InstallLibsCommand); options.Commands[CleanCommand.Name] = typeof(CleanCommand); + options.Commands[CleanLogsCommand.Name] = typeof(CleanLogsCommand); options.Commands[CliCommand.Name] = typeof(CliCommand); options.Commands[ClearDownloadCacheCommand.Name] = typeof(ClearDownloadCacheCommand); options.Commands[RecreateInitialMigrationCommand.Name] = typeof(RecreateInitialMigrationCommand); diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/CleanLogsCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/CleanLogsCommand.cs new file mode 100644 index 0000000000..91d1b07d1f --- /dev/null +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/CleanLogsCommand.cs @@ -0,0 +1,57 @@ +using System.IO; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Extensions.Logging; +using Volo.Abp.Cli.Args; +using Volo.Abp.DependencyInjection; + +namespace Volo.Abp.Cli.Commands; + +public class CleanLogsCommand : IConsoleCommand, ITransientDependency +{ + public const string Name = "clean-logs"; + + public ILogger Logger { get; set; } + + public CleanLogsCommand(ILogger logger) + { + Logger = logger; + } + + public Task ExecuteAsync(CommandLineArgs commandLineArgs) + { + var logsEntries = Directory.EnumerateDirectories(Directory.GetCurrentDirectory(), "Logs", SearchOption.AllDirectories); + + Logger.LogInformation($"Removing 'Logs' files..."); + foreach (var path in logsEntries) + { + var files = Directory.GetFiles(path, "*logs.txt"); + + foreach (var file in files) + { + Logger.LogInformation($"Deleting: {file}"); + File.Delete(file); + } + } + Logger.LogInformation("Logs cleaned successfully!"); + return Task.CompletedTask; + } + + public string GetUsageInfo() + { + var sb = new StringBuilder(); + + sb.AppendLine(""); + sb.AppendLine("Usage:"); + sb.AppendLine(" abp clean-logs"); + sb.AppendLine(""); + sb.AppendLine("See the documentation for more info: https://abp.io/docs/latest/cli"); + + return sb.ToString(); + } + + public static string GetShortDescription() + { + return "Delete all *logs.txt files in the current folder and its subfolders."; + } +} \ No newline at end of file