11using System ;
22using System . Collections . Generic ;
3+ using System . Drawing . Text ;
34using System . IO ;
45using System . Text . RegularExpressions ;
56using System . Threading . Tasks ;
@@ -22,7 +23,7 @@ static class Program
2223 private static readonly byte deactivateByte = 0x00 ;
2324 private static List < GattCharacteristic > listGattCharacteristics = new List < GattCharacteristic > ( ) ;
2425
25-
26+ private static readonly string logFileName = Path . Combine ( Directory . GetCurrentDirectory ( ) , "Logs" ) ;
2627 public delegate void LogHandler ( object msg , LogType type ) ;
2728 public static event LogHandler OnLog ;
2829 private static Form1 app = null ;
@@ -38,6 +39,7 @@ static void Main(string[] args)
3839 Application . ApplicationExit += ( obj , e ) => cancellationToken . Cancel ( ) ;
3940 app = new Form1 ( ) ;
4041 OnLog += ( msg , type ) => app . Log ( msg , type ) ;
42+ LogFileStart ( ) ;
4143 if ( args . Length > 0 )
4244 {
4345 app . ShowInTaskbar = false ;
@@ -232,16 +234,31 @@ private static async void UseArgumentsAsync(string[] args)
232234
233235 private static void Log ( object msg )
234236 {
237+ WriteToLogFile ( msg , LogType . log ) ;
235238 if ( app == null ) return ;
236239 OnLog . Invoke ( msg , LogType . log ) ;
237240 }
238241
239242 private static void LogError ( object msg )
240243 {
244+ WriteToLogFile ( msg , LogType . error ) ;
241245 if ( app == null ) return ;
242246 OnLog . Invoke ( msg , LogType . error ) ;
243247 }
244248
249+ private static void LogFileStart ( )
250+ {
251+ File . WriteAllText ( logFileName , null ) ;
252+ }
253+
254+ private async static Task WriteToLogFile ( object msg , LogType type )
255+ {
256+ string res = $ "[{ DateTime . Now } ]";
257+ res += "[" + ( ( type == LogType . log ) ? "Log" : "ERROR" ) + "] " ;
258+ res += msg . ToString ( ) ;
259+ await File . AppendAllTextAsync ( logFileName , res + "\n " ) ;
260+ }
261+
245262 private static void AppManifest ( WithManifestTask task )
246263 {
247264 EVRInitError evrInitError = EVRInitError . None ;
0 commit comments