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