//on Windows since 1.4.10 public static void Start() { //first define console will be used. //if writer is created ok, then console will NOT be used useConsole = true; //create dir if not exists string dir = UtilAll.GetLogsDir(); if (!Directory.Exists(dir)) { try { Directory.CreateDirectory(dir); } catch { return; } } string filename = UtilAll.GetLogFileCurrent(); string filenameOld = UtilAll.GetLogFileOld(); //if exists, copy to old if (File.Exists(filename)) { try { File.Copy(filename, filenameOld, true); //can be overwritten } catch {} } /* * try { * writer = File.CreateText(filename); * useConsole = false; * } catch {} */ //this does not write until exit //StreamWriter sw = new StreamWriter(new BufferedStream(new FileStream(UtilAll.GetLogFileCurrent(), FileMode.Create))); //this writes all the time StreamWriter sw = new StreamWriter(new FileStream(UtilAll.GetLogFileCurrent(), FileMode.Create)); System.Console.SetOut(sw); System.Console.SetError(sw); sw.AutoFlush = true; }
/* * On Chronojump starts, Log.Start() is called, this copies chronojump_log.txt to chronojump_log_old.txt * a bit later sqliteThings calls: checkIfChronojumpExitAbnormally() and here detects if chrased before * if crashed then the log will be: chronojump_log_old.txt * move this log to crashed logs folder */ public static void CopyOldToCrashed() { //create dir if not exists string dir = UtilAll.GetLogsCrashedDir(); if (!Directory.Exists(dir)) { try { Directory.CreateDirectory(dir); } catch { return; } } string filenameOld = UtilAll.GetLogFileOld(); //if exists, copy to old if (File.Exists(filenameOld)) { try { File.Copy(filenameOld, UtilAll.GetLogCrashedFileTimeStamp(), true); //can be overwritten } catch {} } }
public bool PostCrashLog(string email, string comments) { string filePath = UtilAll.GetLogFileOld(); if (!File.Exists(filePath)) { this.ResultMessage = Catalog.GetString("Could not send file.\nIt does not exist."); return(false); } if (comments != null && comments != "") { Util.InsertTextBeginningOfFile( "----------\nUser comments:\n" + comments + "\n----------\n", filePath); } // Create a request using a URL that can receive a post. WebRequest request = WebRequest.Create(serverUrl + "/backtrace/" + UtilAll.ReadVersionFromBuildInfo() + "-" + email); // Set the Method property of the request to POST. request.Method = "POST"; // Create POST data and convert it to a byte array. byte[] byteArray = readFile(filePath); // Set the ContentType property of the WebRequest. request.ContentType = "application/x-www-form-urlencoded"; // Set the ContentLength property of the WebRequest. request.ContentLength = byteArray.Length; // Get the request stream. Stream dataStream; try { dataStream = request.GetRequestStream(); } catch { LogB.Warning("Error sending datastream"); this.ResultMessage = Catalog.GetString("Could not send file.") + "\n" + string.Format(Catalog.GetString("You are not connected to the Internet\nor {0} server is down."), serverUrl); return(false); } // Write the data to the request stream. dataStream.Write(byteArray, 0, byteArray.Length); // Close the Stream object. dataStream.Close(); // Get the response. WebResponse response; try { response = request.GetResponse(); } catch { LogB.Warning("Error getting response"); this.ResultMessage = Catalog.GetString("Could not send file.") + "\n" + string.Format(Catalog.GetString("You are not connected to the Internet\nor {0} server is down."), serverUrl); return(false); } // Display the status. LogB.Information(((HttpWebResponse)response).StatusDescription); // Get the stream containing content returned by the server. dataStream = response.GetResponseStream(); // Open the stream using a StreamReader for easy access. StreamReader reader = new StreamReader(dataStream); // Read the content. string responseFromServer = reader.ReadToEnd(); // Display the content. LogB.Information(responseFromServer); // Clean up the streams. reader.Close(); dataStream.Close(); response.Close(); JsonValue result = JsonValue.Parse(responseFromServer); string crash_id = result["crash_id"]; LogB.Information("crash_id: ", crash_id); this.ResultMessage = Catalog.GetString("Log sent. Thank you."); return(true); }