@@ -25,7 +25,7 @@ public class Program
2525 public static Dictionary < string , IFileJob > Jobs = new Dictionary < string , IFileJob > ( ) ;
2626 public static void Main ( string [ ] args )
2727 {
28- ConfigureLogger ( ) ;
28+ ConfigureLogger ( args . FirstOrDefault ( ) ) ;
2929 log = LoggerFactory . CreateLogger ( "FileSyncAppMain" ) ;
3030 if ( null != args && args . Length > 0 )
3131 {
@@ -71,7 +71,15 @@ static void RunProgram()
7171 . WithInterval ( TimeSpan . FromMinutes ( 10 ) + TimeSpan . FromSeconds ( 25 ) )
7272 . SyncRecursive ( true )
7373 . Build ( ) ;
74+
7475 jobOptions . Add ( "SyncFromEdgeToLocal" , syncFromEdgeToLocal ) ;
76+ var clean = FileCleanJobOptionsBuilder . CreateBuilder ( )
77+ . WithDestinationPath ( "\\ \\ sbrv\\ share\\ folder" )
78+ . WithFileSyncProvider ( SyncProvider . FileIO )
79+ . WithMaxAge ( TimeSpan . FromDays ( 30 ) )
80+ . Build ( ) ;
81+
82+ jobOptions . Add ( "cleanJob" , clean ) ;
7583
7684 var hostname = Dns . GetHostName ( ) ;
7785
@@ -111,14 +119,22 @@ static void RunProgram()
111119 }
112120
113121
114- public static void ConfigureLogger ( )
122+ public static void ConfigureLogger ( string logLevel )
115123 {
116- if ( LoggingLevel != null )
117- return ;
124+ Exception logLevelException = null ;
118125 LoggingLevel = new LoggingLevelSwitch ( Serilog . Events . LogEventLevel . Information ) ;
119- #if DEBUG
120- LoggingLevel = new LoggingLevelSwitch ( Serilog . Events . LogEventLevel . Verbose ) ;
121- #endif
126+ try
127+ {
128+ if ( ! string . IsNullOrEmpty ( logLevel ) )
129+ {
130+ LoggingLevel = new LoggingLevelSwitch ( ( Serilog . Events . LogEventLevel ) Enum . Parse ( typeof ( Serilog . Events . LogEventLevel ) , logLevel ) ) ;
131+ }
132+ }
133+ catch ( Exception exc )
134+ {
135+ logLevelException = exc ;
136+ }
137+
122138 string serilogFileTemplate = "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {SourceContext:l} {Message:lj}{NewLine}{Exception}" ;
123139 string serilogConsoleTemplate = "{Timestamp:HH:mm:ss.fff}[{Level:u3}]{SourceContext:l} {Message:lj}{NewLine}{Exception}" ;
124140 Serilog . Log . Logger = new LoggerConfiguration ( )
@@ -136,6 +152,10 @@ public static void ConfigureLogger()
136152 . CreateLogger ( ) ;
137153
138154 LoggerFactory = Microsoft . Extensions . Logging . LoggerFactory . Create ( builder => { builder . AddSerilog ( Serilog . Log . Logger ) ; } ) ;
155+ if ( null != logLevelException )
156+ {
157+ Serilog . Log . Error ( logLevelException , "exception setting log level to {A}" , logLevel ) ;
158+ }
139159 }
140160
141161
0 commit comments