using System; using System.IO; namespace Microsoft.Samples.AppUpdater { internal class UpdateLog { private const string LogFileName = "AppUpdate.log"; internal UpdateLog() { string path = Path.Combine(GetLogFilePath(), "AppUpdate.log"); if (!File.Exists(path)) { File.Create(path); File.SetAttributes(path, FileAttributes.Hidden); } } internal void AddSuccess(string versionNumber) { string path = Path.Combine(GetLogFilePath(), "AppUpdate.log"); FileStream stream = File.Open(path, FileMode.Append); StreamWriter streamWriter = new StreamWriter(stream); string value = DateTime.Now.ToString() + ": Successful update to version: " + versionNumber; streamWriter.WriteLine(value); streamWriter.Close(); } internal void AddError(string errorMessage) { string path = Path.Combine(GetLogFilePath(), "AppUpdate.log"); FileStream stream = File.Open(path, FileMode.Append); StreamWriter streamWriter = new StreamWriter(stream); string value = DateTime.Now.ToString() + ": UPDATE FAILED with the following error message:"; streamWriter.WriteLine(value); streamWriter.WriteLine(errorMessage); streamWriter.Close(); } private string GetLogFilePath() { DirectoryInfo directoryInfo = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory); return directoryInfo.Parent.Parent.FullName + "\\"; } } }