12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- using System.Collections.Concurrent;
- using System.IO;
- using WCS.Core;
- namespace ServiceCenter
- {
- public class LogHub
- {
- /// <summary>
- /// 日志队列
- /// </summary>
- public static ConcurrentQueue<LogModel> Logs = new ConcurrentQueue<LogModel>();
- /// <summary>
- /// 发布一条日志记录
- /// </summary>
- /// <param name="path">路径</param>
- /// <param name="title">文件名</param>
- /// <param name="con">内容</param>
- public static void Publish(string path, string title, string con)
- {
- Logs.Enqueue(new LogModel
- {
- path = path,
- Title = title,
- Con = con
- });
- }
- public static void init()
- {
- while (true)
- {
- foreach (var log in Logs)
- {
- if (!Directory.Exists(log.path)) Directory.CreateDirectory(log.path);
- File.AppendAllText(Path.Combine(log.path, log.Title), log.Con);
- }
- Logs.Clear();
- Thread.Sleep(1000);
- }
- }
- }
- public class LogModel
- {
- public string path { get; set; }
- public string Title { get; set; }
- public string Con { get; set; }
- }
- }
|