updatelog.cs
来自「一个饭店管理系统」· CS 代码 · 共 72 行
CS
72 行
using System;
using System.IO;
namespace Microsoft.Samples.AppUpdater
{
//**************************************************************
// UpdateLog Class
// Used to write the updater log file, which records update
// successes & failures to assist debugging.
//**************************************************************
internal class UpdateLog
{
const string LogFileName = "AppUpdate.log";
//**************************************************************
// UpdateLog()
//**************************************************************
internal UpdateLog()
{
string FullLogFilePath = Path.Combine(GetLogFilePath(), LogFileName);
if (!File.Exists(FullLogFilePath))
{
File.Create(FullLogFilePath);
File.SetAttributes(FullLogFilePath,FileAttributes.Hidden);
}
}
//**************************************************************
// AddSuccess()
//**************************************************************
internal void AddSuccess(string versionNumber)
{
string FullLogFilePath = Path.Combine(GetLogFilePath(), LogFileName);
FileStream LogStream = File.Open(FullLogFilePath,FileMode.Append);
StreamWriter SW = new StreamWriter(LogStream);
string StringToWrite;
StringToWrite = DateTime.Now.ToString() + ": Successful update to version: " + versionNumber;
SW.WriteLine(StringToWrite);
SW.Close();
}
//**************************************************************
// AddError()
//**************************************************************
internal void AddError(string errorMessage)
{
string FullLogFilePath = Path.Combine(GetLogFilePath(), LogFileName);
FileStream LogStream = File.Open(FullLogFilePath,FileMode.Append);
StreamWriter SW = new StreamWriter(LogStream);
string StringToWrite;
StringToWrite = DateTime.Now.ToString() + ": UPDATE FAILED with the following error message:";
SW.WriteLine(StringToWrite);
StringToWrite = errorMessage;
SW.WriteLine(StringToWrite);
SW.Close();
}
//**************************************************************
// GetLogFilePath()
//**************************************************************
private string GetLogFilePath()
{
DirectoryInfo DI = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory);
return (DI.Parent.Parent.FullName + @"\");
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?