自定义写日志方法

栏目:云星空知识作者:金蝶来源:金蝶云社区发布:2024-09-16浏览:1

自定义写日志方法

标准产品日志太多,自定义一个写日志到 安装目录\K3Cloud\WebSite\Log ,每天写一个log文件

		private void WriteLog(string log, string strType = "")
		{
			string rootPath = AppDomain.CurrentDomain.BaseDirectory;
			//这个rootPath 老版本 最后无 \ 新版本有? 另外因权限问题,最好是手工创建并授权
			string logPath; // = rootPath + $@"\Log";
			if(rootPath.Substring(rootPath.Length - 1,1).Equals(@"\"))
			{
				logPath = rootPath + $@"Log";
			}
			else
			{
				logPath = rootPath + $@"\Log";
			}
			if (!Directory.Exists(logPath))
				Directory.CreateDirectory(logPath);//创建新路径
			string strLogFile = logPath + "\\log" + DateTime.Now.ToString("yyyyMMdd") + ".log";
			FileStream fs = new FileStream(strLogFile, FileMode.Append);
			StreamWriter sw = new StreamWriter(fs);
			sw.WriteLine(DateTime.Now.ToString() + strType + ":" + log);
			sw.Close();
			fs.Close();
		}


自定义写日志方法

标准产品日志太多,自定义一个写日志到 安装目录\K3Cloud\WebSite\Log ,每天写一个log文件 private void WriteLog(string log, string ...
点击下载文档
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息