需要使用的插件库说明:
Loxodon Framework Log4Net
Version: 1.0.0
© 2016, Clark Yang
=======================================
Thank you for purchasing the plugin!
I hope you enjoy using the product and that it makes your game development faster and easier.
If you have a moment,please leave me a review on the Asset Store.
The version is compatible with MacOSX,Windows,Linux iOS and Android etc.
Requires Loxodon Framework.
https://www.assetstore.unity3d.com/#!/content/77446
Please email yangpc.china@gmail.com for any help or issues.
UPDATE NOTES
----------------------------------------
参考Log4NetExample扩展自己的Loger:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 using System.IO; 2 using Loxodon.Log; 3 using UnityEngine; 4 5 public sealed class ZSLoger 6 { 7 static private ZSLoger _instance; 8 static public ZSLoger Instance 9 { 10 get 11 { 12 if (_instance == null) 13 { 14 _instance = new ZSLoger(); 15 } 16 return _instance; 17 } 18 } 19 20 private ZSLoger() 21 { 22 InitializeLog(); 23 } 24 25 private void InitializeLog() 26 { 27 /* Initialize the log4net */ 28 TextAsset configText = Resources.Load<TextAsset>("Log4NetConfig"); 29 if (configText != null) 30 { 31 using (MemoryStream memStream = new MemoryStream(configText.bytes)) 32 { 33 log4net.Config.XmlConfigurator.Configure(memStream); 34 } 35 } 36 37 /* Initialize the Loxodon.Log.LogManager */ 38 LogManager.Registry(new Log4NetFactory()); 39 } 40 41 public ILog Loger 42 { 43 get 44 { 45 return LogManager.GetLogger(typeof(ZSLoger)); 46 } 47 } 48 }
使用情况:
... 10 public virtual void Enter() 11 { 12 ZSLoger.Instance.Loger.Debug("this is a test, in enter."); 13 } 14 15 public virtual void Exit() 16 { 17 18 } 19 20 public virtual void Update() 21 { 22 23 } 24 } ...
using System.Collections; using System.Collections.Generic; using UnityEngine; public class RunLogicManager : SingletonLimit<RunLogicManager> { private RunningBaseState mState; private Stack<RunningBaseState> mStateStack = new Stack<RunningBaseState>(); public static RunLogicManager Instance { get { return (RunLogicManager)mInstance; } set { mInstance = value; } } private void GotoState(RunningBaseState state) { if (mStateStack.Count > 0) { var tempState = mStateStack.Pop(); tempState.Exit(); } mState = state; mStateStack.Push(mState); mState.Enter(); } // Use this for initialization void Start () { GotoState(RunningBaseState.time); } // Update is called once per frame void Update () { } }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
// 输出情况 2017-11-03 16:12:25,799 Thread[1] DEBUG ZSLoger - this is a test, in enter.