| | |
| | |  |
| | | using Microsoft.AspNetCore.Http; |
| | | using Newtonsoft.Json; |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections.Generic; |
| | |
| | | { |
| | | |
| | | } |
| | | public static void Write_Log(string groupName, string logName, string content, object data = null) |
| | | { |
| | | DateTime nowTime = DateTime.Now; |
| | | string basePath = System.Environment.CurrentDirectory + "/Log/" + $"/{groupName}/{nowTime.ToString("yyyy-MM-dd")}"; |
| | | //妿æ¥å¿æä»¶ç®å½ä¸åå¨,åå建 |
| | | if (!Directory.Exists(basePath)) |
| | | { |
| | | Directory.CreateDirectory(basePath); |
| | | } |
| | | try |
| | | { |
| | | FileStream fs = new FileStream(basePath + "/" + logName + $"{nowTime.ToString("yyMMdd")}.txt", FileMode.Append); |
| | | StreamWriter strwriter = new StreamWriter(fs); |
| | | try |
| | | { |
| | | strwriter.WriteLine(nowTime.ToString() + "." + nowTime.Millisecond); |
| | | strwriter.WriteLine(content); |
| | | if (data != null) |
| | | { |
| | | strwriter.WriteLine(JsonConvert.SerializeObject(data)); |
| | | } |
| | | strwriter.WriteLine("-------------------------------"); |
| | | strwriter.WriteLine(); |
| | | strwriter.Flush(); |
| | | } |
| | | catch { } |
| | | finally |
| | | { |
| | | strwriter.Close(); |
| | | fs.Close(); |
| | | } |
| | | } |
| | | catch { } |
| | | } |
| | | |
| | | public static void WriteApiLog2DB(HttpContext context, string requestParameter, DateTime beginDate, string responseParameter, DateTime endDate, LoggerStatus loggerStatus) |
| | | { |