private void WriteToFile(string rawJsonLine, TwitterConfig config) { // need to deserialize and re-serialize to get rid of \u escaped text dynamic jsonObject = JsonConvert.DeserializeObject(rawJsonLine); var rawJson = JsonConvert.SerializeObject(jsonObject); // Add a new line to the end of the raw JSON for easier separation in the file: rawJson += Environment.NewLine; if (config.CreateBigFile) { string path = Path.Combine(config.FolderName, config.BigFileName); if (File.Exists(path)) { var currentFileSize = new FileInfo(path).Length; if (currentFileSize > config.FileSizeLimit) { // overwrite config and local variable config.InitializeBigFileName(); path = Path.Combine(config.FolderName, config.BigFileName); } } File.AppendAllText(path, rawJson, Encoding.UTF8); } else { string path = Path.Combine(config.FolderName, TwitterConfig.GetTweetFilename()); // Without Encoding it will be written as UTF-8 w/o BOM File.WriteAllText(path, rawJson); } }