LogHelper

using Microsoft.AspNetCore.Hosting;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PT.Common
{
    public class LogHelper
    {


        static string Path = Directory.GetCurrentDirectory();


        private static void Log(string filePath, string message)
        {

            using (StreamWriter streamWriter = new StreamWriter(filePath, true))
            {
                streamWriter.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "  " + message);
                streamWriter.Close();
            }

        }


        public static void DebugLog(string message)
        {

            string filePath = Path + "\\DebugLog_" + DateTime.Now.ToString("yyyy-MM-dd") + ".log";
            Log(filePath, message);

        }


        public static void ErrorLog(string message)
        {

            string filePath = Path + "\\ErrorLog_" + DateTime.Now.ToString("yyyy-MM-dd") + ".log";
            Log(filePath, message);

        }

    }
}

 

posted @ 2023-06-26 11:15  妖狐鬼魅  阅读(9)  评论(0编辑  收藏  举报