Exemple #1
0
        public static void Init(string applicationFolder, string logFileName, StringBuilder appVersionString, string buildTypeString, MyMwcLogEventEnum eventType)
        {
            lock (m_lock)
            {
                try
                {
                    //  Get path to application user-data folder, create new subfolder for MinerWars application and place here log file
                    m_filepath = Path.Combine(applicationFolder, logFileName);
                    MyFileSystemUtils.CreateFolderForFile(m_filepath);
                    m_fileStream = new FileStream(m_filepath, FileMode.Create, FileAccess.Write, FileShare.Read);
                    m_streamWriter = new StreamWriter(m_fileStream);
                    m_enabled = true;
                    m_eventType = eventType;
                }
                catch (Exception)
                {
                    //  Ignore exception - the game must run even if log file can't be used
                }

                m_indentsByThread = new Dictionary<int, int>();
                m_indents = new Dictionary<MyLogIndentKey, MyLogIndentValue>();

                int timezone = (int) Math.Round((DateTime.Now - DateTime.UtcNow).TotalHours);

                WriteLine("Log Started");
                WriteLine(String.Format("Timezone (local - UTC): {0}h", timezone));
                WriteLine("App Version: " + appVersionString);
                WriteLine("Build Type: " + buildTypeString);
            }
        }
Exemple #2
0
        public static void Init(string applicationFolder, string logFileName, StringBuilder appVersionString, string buildTypeString, MyMwcLogEventEnum eventType)
        {
            lock (m_lock)
            {
                try
                {
                    //  Get path to application user-data folder, create new subfolder for MinerWars application and place here log file
                    m_filepath = Path.Combine(applicationFolder, logFileName);
                    MyFileSystemUtils.CreateFolderForFile(m_filepath);
                    m_fileStream   = new FileStream(m_filepath, FileMode.Create, FileAccess.Write, FileShare.Read);
                    m_streamWriter = new StreamWriter(m_fileStream);
                    m_enabled      = true;
                    m_eventType    = eventType;
                }
                catch (Exception)
                {
                    //  Ignore exception - the game must run even if log file can't be used
                }

                m_indentsByThread = new Dictionary <int, int>();
                m_indents         = new Dictionary <MyLogIndentKey, MyLogIndentValue>();

                int timezone = (int)Math.Round((DateTime.Now - DateTime.UtcNow).TotalHours);

                WriteLine("Log Started");
                WriteLine(String.Format("Timezone (local - UTC): {0}h", timezone));
                WriteLine("App Version: " + appVersionString);
                WriteLine("Build Type: " + buildTypeString);
            }
        }
Exemple #3
0
        //  Write an exception on new line
        public static void WriteLine(MyMwcLogEventEnum eventType, Exception ex)
        {
            if (m_enabled == false)
            {
                return;
            }

            WriteLine(eventType, "Exception occured: " + ((ex == null) ? "null" : ex.ToString()));
            if (ex != null && ex.InnerException != null)
            {
                WriteLine(eventType, "Inner Exception: " + ex.InnerException.ToString());
            }
        }
Exemple #4
0
        //  Write a string on EXISTING line
        public static void Write(MyMwcLogEventEnum eventType, string msg)
        {
            if (m_enabled == false)
            {
                return;
            }

            lock (m_lock)
            {
                // If write all or write this event type
                if (m_eventType == MyMwcLogEventEnum.All || eventType == m_eventType)
                {
                    m_streamWriter.Write(GetWithDateTimeAndThreadId(msg));
                    m_streamWriter.Flush();
                }
            }

            //Debug.Write(msg);
        }
Exemple #5
0
        //  Write a string on EXISTING line
        public static void Write(MyMwcLogEventEnum eventType, string msg)
        {
            if (m_enabled == false) return;

            lock (m_lock)
            {
                // If write all or write this event type
                if (m_eventType == MyMwcLogEventEnum.All || eventType == m_eventType)
                {
                    m_streamWriter.Write(GetWithDateTimeAndThreadId(msg));
                    m_streamWriter.Flush();
                }
            }

            //Debug.Write(msg);
        }
Exemple #6
0
        //  Write an exception on new line
        public static void WriteLine(MyMwcLogEventEnum eventType, Exception ex)
        {
            if (m_enabled == false) return;

            WriteLine(eventType, "Exception occured: " + ((ex == null) ? "null" : ex.ToString()));
            if (ex != null && ex.InnerException != null)
            {
                WriteLine(eventType, "Inner Exception: " + ex.InnerException.ToString());
            }
        }