| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- using NLog;
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Net6Demo_Api.Util
- {
- /// <summary>
- /// 日志帮助类
- /// </summary>
- public static class LogHelper
- {
- static readonly ILogger _log;
- static LogHelper()
- {
- _log = LogManager.GetCurrentClassLogger();
- }
- /// <summary>
- /// Error
- /// </summary>
- /// <param name="message"></param>
- /// <param name="ex"></param>
- public static void Error(string message, Exception ex = null)
- {
- if (ex != null)
- {
- _log.Error(ex, message);
- }
- else
- {
- _log.Error(message);
- }
- }
- /// <summary>
- /// Info
- /// </summary>
- /// <param name="message"></param>
- /// <param name="ex"></param>
- public static void Info(string message, Exception ex = null)
- {
- if (ex != null)
- {
- _log.Info(ex, message);
- }
- else
- {
- _log.Info(message);
- }
- }
- /// <summary>
- /// Debug
- /// </summary>
- /// <param name="message"></param>
- /// <param name="ex"></param>
- public static void Debug(string message, Exception ex = null)
- {
- if (ex != null)
- {
- _log.Debug(ex, message);
- }
- else
- {
- _log.Debug(message);
- }
- }
- /// <summary>
- /// Warn
- /// </summary>
- /// <param name="message"></param>
- /// <param name="ex"></param>
- public static void Warn(string message, Exception ex = null)
- {
- if (ex != null)
- {
- _log.Warn(ex, message);
- }
- else
- {
- _log.Warn(message);
- }
- }
- }
- }
|