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

📄 log.cs

📁 小型搜索软件的源代码
💻 CS
字号:
using System;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using ShootSearch.Helper;

namespace ShootSearch.Logging
{
	/// <summary>
	/// Log 的摘要说明。
	/// </summary>
	public class Log
	{
		public Log()
		{
		}
		public static string EchoPath = Directory.GetParent(Assembly.GetExecutingAssembly().Location) + "/log.txt";
		public static string DebugPath = Directory.GetParent(Assembly.GetExecutingAssembly().Location) + "/debug.txt";
		public static bool EchoEnabled = false;
		public static bool DebugEnabled = true;
		private static frmMain m_MainForm;

		public static frmMain MainForm
		{
			get
			{
				return m_MainForm ;
			}
			set
			{
				m_MainForm = value ;
			}
		}

		[MethodImpl(MethodImplOptions.Synchronized)]
		public static void Echo(object obj)
		{
			if (obj == null || MainForm == null)
				return;

			string msg = obj.ToString();
			
			if (EchoPath == null)
				return;

			if (!EchoEnabled)
				return;
			
			MainForm.ConsoleOut(DateTime.Now + " " + msg);
			Console.WriteLine(DateTime.Now + " " + msg);

			using (StreamWriter sw = new StreamWriter(EchoPath, true))
			{
				sw.WriteLine(DateTime.Now + " " + msg);
			}

		}

		[MethodImpl(MethodImplOptions.Synchronized)]
		public static void Debug(object obj)
		{
			if (obj == null)
				return;

			string msg = obj.ToString();

			if (DebugPath == null)
				return;

			if (!DebugEnabled)
				return;

			using (StreamWriter sw = new StreamWriter(DebugPath, true))
			{
				sw.WriteLine(DateTime.Now + " " + msg);
			}
		}

		/// <summary>
		/// 输出处理的URL
		/// </summary>
		/// <param name="obj"></param>
		[MethodImpl(MethodImplOptions.Synchronized)]
		public static void ProcessURL(object obj)
		{	
			if (obj == null || MainForm == null)
				return;

			string msg = obj.ToString();

			if ( Config.ConsoleProcessURL )
			{
				MainForm.ConsoleOut(msg) ;
			}

			Console.WriteLine(DateTime.Now + " " + msg);

		}

		/// <summary>
		/// 输出URL处理结果
		/// </summary>
		/// <param name="obj"></param>
		[MethodImpl(MethodImplOptions.Synchronized)]
		public static void ResultURL(object obj)
		{	
			if (obj == null || MainForm == null)
				return;

			string msg = obj.ToString();

			if ( Config.ConsoleResultURL )
			{
				MainForm.ConsoleOut(msg) ;
			}

			Console.WriteLine(DateTime.Now + " " + msg);
		}

	}
}

⌨️ 快捷键说明

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