Log error to a file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
public class Util
{
public static void RegistarLog(object error)
{
error = string.Format("{0}{0}--------{2} : {3}--------{0}{1}{0}", Environment.NewLine, error, DateTime.Now.ToLongDateString(), DateTime.Now.ToLongTimeString());
System.Text.Encoding encod = System.Text.Encoding.UTF8;
System.IO.FileStream log = System.IO.File.Open(ConfigurationManager.AppSettings.Get("PathLog"), System.IO.FileMode.Append);
log.Write(encod.GetBytes(error.ToString()), 0, encod.GetByteCount(error.ToString()));
log.Close();
}
}
Related examples in the same category