zoukankan      html  css  js  c++  java
  • 集成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 }
    View Code

    使用情况:

    ...
    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.
    View Code
  • 相关阅读:
    有限制的最大连续和问题
    Codevs 5056 潜水员
    Codevs 1958 刺激
    Codevs 3731 寻找道路 2014年 NOIP全国联赛提高组
    [NOIP2014]解方程
    Codevs 3729 飞扬的小鸟
    Codevs 1689 建造高塔
    Codevs 2102 石子归并 2
    C语言基础之进制的那些事(1)
    指针
  • 原文地址:https://www.cnblogs.com/linxmouse/p/7778783.html
Copyright © 2011-2022 走看看