| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- using System;
- using System.IO;
- using log4net;
- using UnityEngine;
- namespace LogHelper
- {
- public static class Log4NetHelper
- {
- static Log4NetHelper()
- {
- string fileName = Path.Combine(Application.dataPath, "Plugins/Log/log4net.config");
- if (!File.Exists(fileName))
- {
- Debug.LogError("Log4Net No Config");
- return;
- }
- var file = new FileInfo(fileName);
- log4net.Config.XmlConfigurator.Configure(file);
- Log2 = LogManager.GetLogger(typeof(Log4NetHelper));
- }
- private static ILog Log { get; set; }
- private static ILog Log2 { get; set; }
- public static void LogInfo(object message)
- {
- Log2.Info(message);
- }
- public static void LogDebug(object message)
- {
- Log2.Debug(message);
- }
- public static void LogError(object message)
- {
- Log2.Error(message);
- }
- public static void LogError(Exception e)
- {
- Log2.Error(e);
- }
- public static void LogFatal(object message)
- {
- Log2.Fatal(message);
- }
- public static void LogFatal(Exception e)
- {
- Log2.Fatal(e);
- }
- public static void LogWarn(object message)
- {
- Log2.Warn(message);
- }
- public static void LogInfo<T>(this T t, object message) where T : class
- {
- Log = LogManager.GetLogger(t.GetType());
- Log.Info(message);
- }
- public static void LogDebug<T>(this T t, object message) where T : class
- {
- Log = LogManager.GetLogger(t.GetType());
- Log.Debug(message);
- }
- public static void LogError<T>(this T t, object message) where T : class
- {
- Log = LogManager.GetLogger(t.GetType());
- Log.Error(message);
- }
- public static void LogError<T>(this T t, Exception e) where T : class
- {
- Log = LogManager.GetLogger(t.GetType());
- Log.Error(e);
- }
- public static void LogFatal<T>(this T t, object message) where T : class
- {
- Log = LogManager.GetLogger(t.GetType());
- Log.Fatal(message);
- }
- public static void LogFatal<T>(this T t, Exception e) where T : class
- {
- Log = LogManager.GetLogger(t.GetType());
- Log.Fatal(e);
- }
- public static void LogWarn<T>(this T t, object message) where T : class
- {
- Log = LogManager.GetLogger(t.GetType());
- Log.Warn(message);
- }
- }
- }
|