2013-07-12 22 views
-2

我正在開發Windows Phone 8中的VoIP應用程序(撥號程序),在那個應用程序中包含撥號盤,通訊錄,通話記錄,我已經創建了撥號盤和聯繫人列表,我需要開發一個在該應用程序中調用日誌功能。我努力爲Windows Phone 8創建呼叫記錄請任何幫助在Windows Phone 8中的通話記錄功能

回答

0

這是一個創建XML文件的類,它保存所有呼叫的日誌。您沒有足夠詳細地說明問題,或者您想要做什麼,或者您已經嘗試了什麼。所以這裏是你應該實現什麼的想法:

public class Logger 
{ 
private static string logPath; 
public Logger() 
{ 
    logPath = "/Logs/log.xml"; 
} 

public void LogData(string contactName, string duration) 
{ 
    Object thisLock = new Object(); 
    logPath += DateTime.Now.ToShortDateString().Replace('.', '_') + ".log"; 
    XmlDocument doc = new XmlDocument(); 

    lock (thisLock) 
    { 
     try 
     { 
      XmlNode root = null; 

      if (File.Exists(logPath)) 
      { 
       doc.Load(logPath); 
       root = doc.SelectSingleNode("/Call"); 
      } 
      else 
      { 
       doc.AppendChild(doc.CreateXmlDeclaration("1.0", "UTF-8", null)); 
       root = doc.AppendChild(doc.CreateElement("Call")); 
      } 

      XmlElement call = doc.CreateElement("call"); 
      root.AppendChild(call); 

      XmlElement xcontactName = doc.CreateElement("contactName"); 
      xcontactName.InnerText = contactName; 
      call.AppendChild(xcontactName); 

      XmlElement xdate = doc.CreateElement("date"); 
      xdate.InnerText = DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss"); 
      call.AppendChild(xdate); 

      XmlElement xduration = doc.CreateElement("duration"); 
      xduration.InnerText = duration; 
      call.AppendChild(xduration); 

      doc.Save(logPath); 
     } 
     catch (Exception e) 
     { 
      Debug.WriteLine(e.Message); 
     } 
    } 
}