@@ -52,7 +52,7 @@ public class GameStateRunActivity : GameState
5252
5353 static Viewer Viewer { get { return Program . Viewer ; } set { Program . Viewer = value ; } }
5454 static ORTraceListener ORTraceListener { get { return Program . ORTraceListener ; } set { Program . ORTraceListener = value ; } }
55- static string logFileName { get { return Program . logFileName ; } set { Program . logFileName = value ; } }
55+ static string logFilePath { get { return Program . logFileName ; } set { Program . logFileName = value ; } }
5656 static string EvaluationFilename { get { return Program . EvaluationFilename ; } set { Program . EvaluationFilename = value ; } }
5757
5858 /// <summary>
@@ -811,13 +811,30 @@ void InitLogging(UserSettings settings, string[] args, bool appendLog)
811811 {
812812 fileName = settings . LoggingFilename ;
813813 }
814- logFileName = GetFilePath ( settings , fileName ) ;
814+ logFilePath = GetFilePath ( settings , fileName ) ;
815815
816816 // Ensure we start with an empty file.
817817 if ( ! appendLog )
818- File . Delete ( logFileName ) ;
818+ {
819+ if ( File . Exists ( logFilePath ) )
820+ {
821+ try
822+ {
823+ var logFileExtension = Path . GetExtension ( logFilePath ) ;
824+ var prevLogPath = Path . ChangeExtension ( logFilePath , ".prev" + logFileExtension ) ;
825+ if ( File . Exists ( prevLogPath ) ) { File . Delete ( prevLogPath ) ; }
826+ File . Move ( logFilePath , prevLogPath ) ;
827+ }
828+ catch ( Exception e )
829+ {
830+ Console . WriteLine ( "Failed to move log file: " + e . Message ) ;
831+ File . Delete ( logFilePath ) ;
832+ }
833+ }
834+ }
835+
819836 // Make Console.Out go to the log file AND the output stream.
820- Console . SetOut ( new FileTeeLogger ( logFileName , Console . Out ) ) ;
837+ Console . SetOut ( new FileTeeLogger ( logFilePath , Console . Out ) ) ;
821838 // Make Console.Error go to the new Console.Out.
822839 Console . SetError ( Console . Out ) ;
823840 }
@@ -836,8 +853,8 @@ void InitLogging(UserSettings settings, string[] args, bool appendLog)
836853 LogSeparator ( ) ;
837854 Console . WriteLine ( "Version = {0}" , VersionInfo . Version . Length > 0 ? VersionInfo . Version : "<none>" ) ;
838855 Console . WriteLine ( "Build = {0}" , VersionInfo . Build ) ;
839- if ( logFileName . Length > 0 )
840- Console . WriteLine ( "Logfile = {0}" , logFileName ) ;
856+ if ( logFilePath . Length > 0 )
857+ Console . WriteLine ( "Logfile = {0}" , logFilePath ) ;
841858 Console . WriteLine ( "Executable = {0}" , Path . GetFileName ( ApplicationInfo . ProcessFile ) ) ;
842859 foreach ( var arg in args )
843860 Console . WriteLine ( "Argument = {0}" , arg ) ;
@@ -1045,8 +1062,8 @@ void UninitLoading()
10451062
10461063 static void CopyLog ( string toFile )
10471064 {
1048- if ( logFileName . Length == 0 ) return ;
1049- File . Copy ( logFileName , toFile , true ) ;
1065+ if ( logFilePath . Length == 0 ) return ;
1066+ File . Copy ( logFilePath , toFile , true ) ;
10501067 }
10511068
10521069 void InitSimulator ( UserSettings settings , string [ ] args , string mode )
0 commit comments