當前位置: 首頁>>代碼示例>>C#>>正文


C# LogStore類代碼示例

本文整理匯總了C#中System.IO.Log.LogStore的典型用法代碼示例。如果您正苦於以下問題:C# LogStore類的具體用法?C# LogStore怎麽用?C# LogStore使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


LogStore類屬於System.IO.Log命名空間,在下文中一共展示了LogStore類的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ArchiveToXML

class LogBackup
{ 
    static void ArchiveToXML(LogStore logStore, string fileName) 
    {  
        LogArchiveSnapshot snapshot = logStore.CreateLogArchiveSnapshot();
        
        XmlTextWriter writer = new XmlTextWriter(fileName, Encoding.ASCII);
        
        writer.WriteStartElement("logArchive");
        foreach(FileRegion region in snapshot.ArchiveRegions) 
        {
            writer.WriteStartElement("fileRegion"); 
            writer.WriteElementString("path", region.Path); 
            writer.WriteElementString("length", region.FileLength.ToString()); 
            writer.WriteElementString("offset", region.Offset.ToString()); 
            using(Stream dataStream = region.GetStream()) 
            { 
                byte[] data = new byte[dataStream.Length]; 
                dataStream.Read(data, 0, data.Length); 
                writer.WriteElementString("data", Convert.ToBase64String(data)); 
            }
            writer.WriteEndElement();
        }
        writer.WriteEndElement(); 
        writer.Close(); 
        logStore.SetArchiveTail(snapshot.LastSequenceNumber); 
    }
    static void RestoreFromXML(string fileName) 
    { 
        using(XmlTextReader reader = new XmlTextReader(fileName)) 
        {
            reader.ReadStartElement("logArchive"); 
            while(reader.IsStartElement()) 
            { 
                string path = reader.ReadElementString("path"); 
                long length = Int64.Parse(reader.ReadElementString("length")); 
                long offset = Int64.Parse(reader.ReadElementString("offset")); 
                string dataString = reader.ReadElementString("data"); 
                byte[] data = Convert.FromBase64String(dataString); 
                FileStream fileStream;
                using(fileStream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write)) 
                { 
                    fileStream.SetLength(length); 
                    fileStream.Position = offset; fileStream.Write(data, 0, data.Length); 
                }
            } 
        reader.ReadEndElement(); 
        } 
    } 
}
開發者ID:.NET開發者,項目名稱:System.IO.Log,代碼行數:50,代碼來源:LogStore


注:本文中的System.IO.Log.LogStore類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。