一,您选择用什么样的日志组件

日志组件,不得不提大名鼎鼎的Log4Net。比较常用的还有 Enterprise Library Logging,ServiceStack Logging。当然您还可以补充,我就只用过这几款。

上边提到的3款日志组件,都要在.config里加代码,特别是Log4Net,还要把SQL写在配置里。我就是仅仅只写个日志,还要配置这么多信息,让人略有不爽。

所以在很长一段时间里,我用下边这个方法写日志:

        private static void WriteText(string logPath, string logContent)
        {
            try
            {
                if (!File.Exists(logPath))
                {
                    File.CreateText(logPath).Close();
                }
                StreamWriter sw = File.AppendText(logPath);
                sw.Write(logContent);
                sw.Close();
            }
            catch (Exception ex)
            {
                
            }
            finally
            {

            }
        }
View Code

相关文章:

  • 2021-10-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-21
  • 2021-07-28
  • 2021-08-19
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-10-03
  • 2021-11-27
  • 2023-02-03
  • 2022-12-23
  • 2022-01-06
相关资源
相似解决方案