集成Log4Net到自己的Unity工程
需要使用的插件库说明:
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:

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 () { } }

// 输出情况 2017-11-03 16:12:25,799 Thread[1] DEBUG ZSLoger - this is a test, in enter.
分类:
Unity3d
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 通过 API 将Deepseek响应流式内容输出到前端
· AI Agent开发,如何调用三方的API Function,是通过提示词来发起调用的吗