c#简单日志类

2021-03-10 04:27

阅读:384

标签:help   style   dir   try   ade   nal   current   ignore   exit   

 public class LogHelper
    {
        private static readonly ReaderWriterLockSlim LogWriteLock = new ReaderWriterLockSlim();
        private static readonly string LogFilePath = Environment.CurrentDirectory + "\\log.txt";
        public static void Log(string content)
        {
            try
            {
                LogWriteLock.EnterWriteLock();

                string data = DateTime.Now + ":" + content+Environment.NewLine;

                File.AppendAllText(LogFilePath, data);
            }
            catch (Exception)
            {
                // ignored
            }
            finally
            {
                LogWriteLock.ExitWriteLock();
            }
        }

    }

 

c#简单日志类

标签:help   style   dir   try   ade   nal   current   ignore   exit   

原文地址:https://www.cnblogs.com/chlm/p/12720069.html


评论


亲,登录后才可以留言!