You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
107 lines
2.8 KiB
C#
107 lines
2.8 KiB
C#
using GuideScreen.Common.Common;
|
|
using GuideScreen.Common.Services;
|
|
using GuideScreen.Common.Services.Models;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.Data.Entity.Infrastructure.Design;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace GuideScreen.Common
|
|
{
|
|
/// <summary>
|
|
/// 日志扩展
|
|
/// </summary>
|
|
public static class LogExtensions
|
|
{
|
|
private static ILogService logService;
|
|
|
|
static LogExtensions()
|
|
{
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 日志服务
|
|
/// </summary>
|
|
public static ILogService LogService
|
|
{
|
|
get
|
|
{
|
|
if (logService == null)
|
|
{
|
|
logService = DIManager.GetContainerObject<ILogService>();
|
|
|
|
logService.LogMessage += (model) =>
|
|
{
|
|
Trace.WriteLine($"{model.Time} {model.LogLevel} {model.Source} {model.Message}");
|
|
};
|
|
}
|
|
return logService;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 写入Error级别日志
|
|
/// </summary>
|
|
/// <param name="ex">异常对象</param>
|
|
public static void WriteErrorLog(this Exception ex)
|
|
{
|
|
var error = new StringBuilder(ex.Message);
|
|
error.AppendLine();
|
|
error.AppendLine(ex.StackTrace);
|
|
LogService.Error(error.ToString());
|
|
}
|
|
|
|
/// <summary>
|
|
/// 写入Fatal级别日志
|
|
/// </summary>
|
|
/// <param name="ex">异常对象</param>
|
|
public static void WriteFatalLog(this Exception ex)
|
|
{
|
|
var error = new StringBuilder(ex.Message);
|
|
error.AppendLine();
|
|
error.AppendLine(ex.StackTrace);
|
|
LogService.Fatal(error.ToString());
|
|
}
|
|
|
|
/// <summary>
|
|
/// 写入info级别日志
|
|
/// </summary>
|
|
/// <param name="str"></param>
|
|
public static void WriteInfoLog(this string str)
|
|
{
|
|
LogService.Info(str);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 写入debug级别日志
|
|
/// </summary>
|
|
/// <param name="str"></param>
|
|
public static void WriteDebugLog(this string str)
|
|
{
|
|
LogService.Debug(str);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 写入Error级别日志
|
|
/// </summary>
|
|
/// <param name="str"></param>
|
|
public static void WriteErrorLog(this string str)
|
|
{
|
|
LogService.Error(str);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 写入Error级别日志
|
|
/// </summary>
|
|
/// <param name="str"></param>
|
|
public static void WriteFatalLog(this string str)
|
|
{
|
|
LogService.Fatal(str);
|
|
}
|
|
}
|
|
}
|