This class has been adapted from www.valion-game.com/295/use-log4net-for-efficient-logging-in-unity3d/
Inheritance: log4net.Appender.MemoryAppender
Esempio n. 1
0
        private void Awake()
        {
            if (_initialized) {
                return;
            }
            _initialized = true;

            // initialize log4net
            ConfigureLog();

            Log<UnityLogWindow>.Info("Logging system started");
            Log<UnityLogWindow>.Info("Operating System: " + SystemInfo.operatingSystem);
            Log<UnityLogWindow>.Info("System Spec: " + SystemInfo.processorType + " - #" + SystemInfo.processorCount + " (" + SystemInfo.systemMemorySize + ")");
            Log<UnityLogWindow>.Info("Device Spec: " + SystemInfo.deviceName + " " + SystemInfo.deviceModel + " [" + SystemInfo.deviceUniqueIdentifier + "]");
            Log<UnityLogWindow>.Info("Graphic Spec: " + SystemInfo.graphicsDeviceID + ":" + SystemInfo.graphicsDeviceName + " - "
             + SystemInfo.graphicsDeviceVendorID + ":" + SystemInfo.graphicsDeviceVendor + " (" + SystemInfo.graphicsMemorySize + "MB, Shader Level " + SystemInfo.graphicsShaderLevel + ")");

            // default window state
            int margins = 40;
            _windowRect = new Rect(margins, margins, Screen.width - 2 * margins, Screen.height - 2 * margins);

            // get our log appender
            Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();
            IAppender[] appenders = hierarchy.GetAppenders();
            foreach (IAppender appender in appenders) {
                if (appender is UnityLogAppender) {
                    _logAppender = (UnityLogAppender)appender;
                    break;
                }
            }

            if (_logAppender == null) {
                Debug.LogWarning("There is not UnityLogAppender; there will be no in-game logging support");
            }
        }
Esempio n. 2
0
        private void ConfigureAppenders()
        {
            PatternLayout layout = new PatternLayout();
            layout.ConversionPattern = "%date [%thread] %-5level %logger - %message%n";
            layout.ActivateOptions();

            UnityLogAppender logAppender = new UnityLogAppender();
            logAppender.MaximumEntries = 600;
            logAppender.Threshold = log4net.Core.Level.Debug;
            logAppender.Layout = layout;
            logAppender.ActivateOptions();

            if (Application.isWebPlayer) {
                UnityEngine.Debug.Log("Detected Web-Player, only using appended logger");
                BasicConfigurator.Configure(logAppender);
                return;
            }

            ConsoleAppender consoleAppener = new ConsoleAppender();
            consoleAppener.Layout = layout;
            consoleAppener.Threshold = log4net.Core.Level.Debug;
            consoleAppener.Target = ConsoleAppender.ConsoleOut;
            consoleAppener.ActivateOptions();

            PatternLayout fileLayout = new PatternLayout();
            fileLayout.ConversionPattern = "%date [%thread] %-5level %logger - %message%n";
            fileLayout.ActivateOptions();

            FileAppender fileAppender = new FileAppender();
            fileAppender.AppendToFile = true;
            fileAppender.Threshold = log4net.Core.Level.Debug;
            fileAppender.File = string.Format("Logs/log_{0:MM-dd-yyyy_HH-mm-ss}.txt", DateTime.Now);
            fileAppender.Layout = fileLayout;
            fileAppender.ImmediateFlush = false;
            fileAppender.ActivateOptions();

            UnityEngine.Debug.Log("log4net is targeting file " + fileAppender.File);
            BasicConfigurator.Configure(fileAppender, logAppender, consoleAppener);
        }