自定义写日志方法原创
金蝶云社区-湖南吴双得
湖南吴双得
45人赞赏了该文章 455次浏览 未经作者许可,禁止转载编辑于2023年03月30日 13:33:56

标准产品日志太多,自定义一个写日志到 安装目录\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();
		}


图标赞 45
45人点赞
还没有人点赞,快来当第一个点赞的人吧!
图标打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!

您的鼓励与嘉奖将成为创作者们前进的动力,如果觉得本文还不错,可以给予作者创作打赏哦!

请选择打赏金币数 *

10金币20金币30金币40金币50金币60金币
可用金币: 0