Skip to content

Commit 8b4f5c3

Browse files
authored
Merge pull request #23305 from blackWins/cli
Add CleanLogsCommand
2 parents 36546b2 + 4f2a84d commit 8b4f5c3

3 files changed

Lines changed: 68 additions & 0 deletions

File tree

docs/en/cli/index.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Here is the list of all available commands before explaining their details:
4343
* **[`new-package`](../cli#new-package)**: Generates a new package based on the given template.
4444
* **[`update`](../cli#update)**: Automatically updates all ABP related NuGet and NPM packages in a solution.
4545
* **[`clean`](../cli#clean)**: Deletes all `BIN` and `OBJ` folders in the current folder.
46+
* **[`clean-logs`](../cli#clean-logs)**: Delete all `*logs.txt` files in the current folder and its subfolders.
4647
* **[`add-package`](../cli#add-package)**: Adds an ABP package to a project.
4748
* **[`add-package-ref`](../cli#add-package-ref)**: Adds package to given project.
4849
* **[`install-module`](../cli#install-module)**: Adds a [multi-package application module](../modules/index.md) to a given module.
@@ -369,6 +370,15 @@ Usage:
369370
````bash
370371
abp clean
371372
````
373+
### clean-logs
374+
375+
Delete all `*logs.txt` files in the current folder and its subfolders.
376+
377+
Usage:
378+
379+
````bash
380+
abp clean-logs
381+
````
372382

373383

374384
### add-package

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/AbpCliCoreModule.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public override void ConfigureServices(ServiceConfigurationContext context)
7575
options.Commands[CreateMigrationAndRunMigratorCommand.Name] = typeof(CreateMigrationAndRunMigratorCommand);
7676
options.Commands[InstallLibsCommand.Name] = typeof(InstallLibsCommand);
7777
options.Commands[CleanCommand.Name] = typeof(CleanCommand);
78+
options.Commands[CleanLogsCommand.Name] = typeof(CleanLogsCommand);
7879
options.Commands[CliCommand.Name] = typeof(CliCommand);
7980
options.Commands[ClearDownloadCacheCommand.Name] = typeof(ClearDownloadCacheCommand);
8081
options.Commands[RecreateInitialMigrationCommand.Name] = typeof(RecreateInitialMigrationCommand);
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using System.IO;
2+
using System.Text;
3+
using System.Threading.Tasks;
4+
using Microsoft.Extensions.Logging;
5+
using Volo.Abp.Cli.Args;
6+
using Volo.Abp.DependencyInjection;
7+
8+
namespace Volo.Abp.Cli.Commands;
9+
10+
public class CleanLogsCommand : IConsoleCommand, ITransientDependency
11+
{
12+
public const string Name = "clean-logs";
13+
14+
public ILogger<CleanCommand> Logger { get; set; }
15+
16+
public CleanLogsCommand(ILogger<CleanCommand> logger)
17+
{
18+
Logger = logger;
19+
}
20+
21+
public Task ExecuteAsync(CommandLineArgs commandLineArgs)
22+
{
23+
var logsEntries = Directory.EnumerateDirectories(Directory.GetCurrentDirectory(), "Logs", SearchOption.AllDirectories);
24+
25+
Logger.LogInformation($"Removing 'Logs' files...");
26+
foreach (var path in logsEntries)
27+
{
28+
var files = Directory.GetFiles(path, "*logs.txt");
29+
30+
foreach (var file in files)
31+
{
32+
Logger.LogInformation($"Deleting: {file}");
33+
File.Delete(file);
34+
}
35+
}
36+
Logger.LogInformation("Logs cleaned successfully!");
37+
return Task.CompletedTask;
38+
}
39+
40+
public string GetUsageInfo()
41+
{
42+
var sb = new StringBuilder();
43+
44+
sb.AppendLine("");
45+
sb.AppendLine("Usage:");
46+
sb.AppendLine(" abp clean-logs");
47+
sb.AppendLine("");
48+
sb.AppendLine("See the documentation for more info: https://abp.io/docs/latest/cli");
49+
50+
return sb.ToString();
51+
}
52+
53+
public static string GetShortDescription()
54+
{
55+
return "Delete all *logs.txt files in the current folder and its subfolders.";
56+
}
57+
}

0 commit comments

Comments
 (0)