⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uploadloger.cs

📁 比较实用的上传控件
💻 CS
字号:
using System;
using System.IO;
using System.Diagnostics;

namespace Webb.WAVE.Controls.Upload2
{
	/// <summary>
	/// Summary description for UploadLog.
	/// </summary>
	public class UploadLoger:IDisposable
	{
		#region Fields
		private static DateTime M_LogTime;
		private TextWriter m_fs;
		private string m_uploadGUID;
		static string M_logPath	= Path.Combine(UploadHelper.M_WebPath,"UploadLog");
		#endregion

		#region properties
		public  TextWriter Writer
		{
			get
			{
				if(this.m_fs!=null)
				{
					return this.m_fs;
				}
				else
				{
					this.OpenLogFile();
					return this.m_fs;
				}
			}
		}
		public string LogGUID
		{
			get{return this.m_uploadGUID;}
			set{this.m_uploadGUID=value;}
		}
		#endregion

		public UploadLoger()
		{
			//
			// TODO: Add constructor logic here
			//
			if(!Directory.Exists(UploadLoger.M_logPath))
			{
				Directory.CreateDirectory(UploadLoger.M_logPath);
			}
			TimeSpan m_timespan = DateTime.Now.Subtract(UploadLoger.M_LogTime);
			if(m_timespan.Days>=1)
			{
				string m_logName = DateTime.Now.ToString("yyyyMMdd")+".log";
				m_logName = Path.Combine(UploadLoger.M_logPath,m_logName);
                UploadLoger.M_LogTime = DateTime.Now;
				Trace.Listeners.Clear();
				Trace.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(m_logName));
			}
		}

		static UploadLoger()
		{
			string m_logName = DateTime.Now.ToString("yyyyMMdd")+".log";
			m_logName = Path.Combine(UploadLoger.M_logPath,m_logName);
			UploadLoger.M_LogTime	= DateTime.Now;
			Trace.Listeners.Clear();
			//Trace.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(m_logName));
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="i_log"></param>
		public void WriteLine(string i_log)
		{
			Trace.WriteLine(string.Format("{0}\t{1}\t{2}.",DateTime.Now,this.m_uploadGUID,i_log));
		}

		/// <summary>
		/// 
		/// </summary>
		public void OpenLogFile()
		{
			string m_fileName	= Path.Combine(UploadLoger.M_logPath,this.m_uploadGUID+".log");
			if(File.Exists(m_fileName))
			{
				this.m_fs	= File.AppendText(m_fileName);
			}
			else
			{
				this.m_fs	= File.CreateText(m_fileName);
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public void CloseLogFile()
		{
			if(this.m_fs!=null)
			{
				this.m_fs.Flush();
				this.m_fs.Close();
				this.m_fs	= null;
			}
		}

		#region IDisposable Members
		public void Dispose()
		{
			// TODO:  Add UploadLog.Dispose implementation
			if(this.m_fs!=null)
			{
				this.m_fs.Flush();
				this.m_fs.Close();
				this.m_fs	= null;
			}
			Trace.Flush();
		}
		#endregion
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -