Exemplo n.º 1
0
        public static void Log(LogLevel level, string category, string message, bool stackTrace)
        {
            if (level == LogLevel.None && category == null && message == null && !stackTrace)
            {
                return;
            }

            if (IsLogging())
            {
                bool c = true;
                if (niec_native_func.cache_done_niecmod_native_file_create && niec_native_func.cache_done_niecmod_native_file_write)
                {
                    if (!niec_std.is_valid_handle(fileLogHandle))
                    {
                        fileLogHandle = niec_native_func.niecmod_native_file_create("Sims 3 Logs\\" + "NiecMod Log " + NFinalizeDeath.GetNowTimeToStr() + ".log");
                    }
                    if (!niec_std.is_valid_handle(fileLogHandle))
                    {
                        fileLogHandle = niec_native_func.niecmod_native_file_create("C:\\Sims 3 Logs\\" + "NiecMod Log " + NFinalizeDeath.GetNowTimeToStr() + ".log");
                    }
                    if (niec_std.is_valid_handle(fileLogHandle))
                    {
                        //if (level != LogLevel.None)
                        //    niec_native_func.niecmod_native_file_writetext(fileLogHandle,DateTime.Now.ToString("T") + " Level: " + level);
                        //if (category != null)
                        //    niec_native_func.niecmod_native_file_writetext(fileLogHandle, DateTime.Now.ToString("T") + " Category: " + category);
                        //
                        //niec_native_func.niecmod_native_file_writetext(fileLogHandle, DateTime.Now.ToString("T") + (message != null && message.Length > 0 ? " Message: " + message : " No Message"));
                        //
                        //if (stackTrace)
                        //    niec_native_func.niecmod_native_file_writetext(fileLogHandle, DateTime.Now.ToString("T") + " Stack Trace:\n" + CurrentStack());
                        //

                        if (level != LogLevel.None)
                        {
                            c = niec_native_func.WriteTextToFileA(fileLogHandle, DateTime.Now.ToString("T") + ": Level: " + level + "\n") == 1;
                        }

                        if (!c)
                        {
                            goto t;
                        }

                        if (category != null)
                        {
                            c = niec_native_func.WriteTextToFileA(fileLogHandle, DateTime.Now.ToString("T") + ": Category: " + category + "\n") == 1;
                        }

                        if (!c)
                        {
                            goto t;
                        }

                        c = niec_native_func.WriteTextToFileA
                                (fileLogHandle, DateTime.Now.ToString("T") + (message != null && message.Length > 0 ? ": Message: " + message : ": No Message") + "\n") == 1;

                        if (!c)
                        {
                            goto t;
                        }

                        if (stackTrace)
                        {
                            var ttt = DateTime.Now.ToString("T") + ": Stack Trace:\n" + GetCurrentStack() + "\n";
                            fileLogHandleC += ttt.Length;
                            c = niec_native_func.WriteTextToFileA(fileLogHandle, ttt) == 1;
                        }
                        if (!c)
                        {
                            goto t;
                        }

                        // niec_native_func.WriteTextToFileA(fileLogHandle, "\n\n\n");

                        fileLogHandleC += (message != null ? message.Length : 0);
                        if (fileLogHandleC > 3500000)
                        {
                            fileLogHandleC = 0;
                            niec_native_func.niecmod_native_file_close(fileLogHandle);
                            fileLogHandle = default(IntPtr);
                        }

                        niec_native_func.OutputDebugString("NDebugger created log Done.");
                        return;
                    }
                    else
                    {
                        c = false;
                    }
                }

t:
                if (!c)
                {
                    fileLogHandleC = 0;
                    fileLogHandle  = default(IntPtr);
                }

                niec_native_func.OutputDebugString("NDebugger log");

                if (level != LogLevel.None)
                {
                    niec_native_func.OutputDebugString("Level: " + level);
                }
                if (category != null)
                {
                    niec_native_func.OutputDebugString("Category: " + category);
                }

                niec_native_func.OutputDebugString(message != null && message.Length > 0 ? "Message: " + message : "No Message");

                if (stackTrace)
                {
                    niec_native_func.OutputDebugString("Stack Trace:\n" + GetCurrentStack());
                }
            }
        }
Exemplo n.º 2
0
        public static bool LogLite(string text)
        {
            if (!(niec_native_func.cache_done_niecmod_native_file_create && niec_native_func.cache_done_niecmod_native_file_write))
            {
                return(false);
            }

            if (text == null || text.Length == 0)
            {
                text = "LogLite: no text";
            }
            if (!niec_std.is_valid_handle(fileLogHandleL))
            {
                if (!niec_std.is_valid_handle(fileLogHandleL))
                {
                    fileLogHandleL = niec_native_func.niecmod_native_file_create("Sims 3 Logs\\" + "NiecMod LogL " + NFinalizeDeath.GetNowTimeToStr() + ".log");
                }
                if (!niec_std.is_valid_handle(fileLogHandleL))
                {
                    fileLogHandleL = niec_native_func.niecmod_native_file_create("C:\\Sims 3 Logs\\" + "NiecMod LogL " + NFinalizeDeath.GetNowTimeToStr() + ".log");
                }
                if (!niec_std.is_valid_handle(fileLogHandleL))
                {
                    niec_native_func.OutputDebugString("NDebugger:LogLite failed to create file!");
                    return(false);
                }
            }

            var yyy = DateTime.Now.ToString("T") + ": " + text;
            var ttt = niec_native_func.WriteTextToFileA(fileLogHandleL, yyy) == 1;

            if (ttt)
            {
                fileLogHandleCL += yyy.Length;
                if (fileLogHandleCL > 1500000)
                {
                    fileLogHandleCL = 0;
                    niec_native_func.niecmod_native_file_close(fileLogHandleL);
                    fileLogHandleL = default(IntPtr);
                }
            }
            else
            {
                fileLogHandleCL = 0; fileLogHandleL = default(IntPtr);
            }

            return(ttt);
        }