예제 #1
0
        }                                                   /*}}}*/

        public static void write(string data, zLEVEL level) /*{{{
                                                             */
        {
            if (zlog.isQuit)
            {
                return;
            }

            // Determine if this thread have Name?
            string threadName = "";

            if (Thread.CurrentThread.Name != null)
            {
                threadName = Thread.CurrentThread.Name.Trim();
            }
            if (threadName.Length > 0)
            {
                threadName = "{" + threadName + "} ";
            }

            // Build log Packet and Enqueue to Master Thread
            zPACKET pk = new zPACKET(threadName + data, level);

            pk.isWriteFile    = isWriteFile;
            pk.isWriteConsole = isWriteConsole;
            pk.isWriteClient  = isWriteClient;
            pk.isWriteServer  = isWriteServer;
            lock (queMaster.SyncRoot) { queMaster.Enqueue(pk); }
        }       /*}}}*/
예제 #2
0
        }                                          /*}}}*/

        private static void _thread_write_server() /*{{{
                                                    */
        {
            zlog.isStartOK_WriteServer = true;
            zlog.debug("zLog Thread_WriteServer ... Start");

            // Check and Init Server Port
            if (zlog.serverPort > 0)
            {
                if (zlog.serverIp.Trim().Length == 0)
                {
                    zlog.serverIp = "127.0.0.1";
                }
                // Not Init client for send log to server
            }

            // Main LOOP for cycle each Log Packet Queue
            while (!zlog.isQuit)
            {
                Thread.Sleep(0);
                lock (queWriteServer.SyncRoot)
                {
                    if (queWriteServer.Count > 0)
                    {
                        zPACKET pk = (zPACKET)queWriteServer.Dequeue();
                        // Do something with Log Packet, Then continue next packet
                        pk = null;
                        continue;
                    }
                }
                Thread.Sleep(1);
            }
        }                                                                                                       /*}}}*/
예제 #3
0
        }                                          /*}}}*/

        private static void _thread_write_client() /*{{{
                                                    */
        {
            zlog.isStartOK_WriteClient = true;
            zlog.debug("zLog Thread_WriteClient ... Start");

            // Check Client Port and Init Client Service
            if (zlog.clientPort > 0)
            {
                // Init and Listen TCP Server for client connect
            }

            // Main LOOP for cycle each Log Packet Queue
            while (!zlog.isQuit)
            {
                Thread.Sleep(0);
                lock (queWriteClient.SyncRoot)
                {
                    if (queWriteClient.Count > 0)
                    {
                        zPACKET pk = (zPACKET)queWriteClient.Dequeue();
                        // Do something with Log Packet, Then continue next packet
                        pk = null;
                        continue;
                    }
                }
                Thread.Sleep(1);
            }
        }                                          /*}}}*/
예제 #4
0
        }                                        /*}}}*/

        private static void _thread_write_file() /*{{{
                                                  */
        {
            zlog.debug("zLog Thread_WriteFile ... Start");
            zlog.debug("zLog Thread_WriteFile ... folderLog = " + zlog.folderLog);

            // Check and Create Folder
            if (!Directory.Exists(zlog.folderLog))
            {
                try
                {
                    Directory.CreateDirectory(zlog.folderLog);
                }
                catch (Exception ex)
                {
                    zlog.lastError = "Thread WriteFile cannot create Director! {" + ex.Message + "}";
                    return;
                }
            }

            // This point we can say this thread is start success
            zlog.isStartOK_WriteFile = true;

            // Main LOOP for cycle each Log Packet Queue
            while (!zlog.isQuit)
            {
                Thread.Sleep(0);
                lock (queWriteFile.SyncRoot)
                {
                    if (queWriteFile.Count > 0)
                    {
                        zPACKET pk = (zPACKET)queWriteFile.Dequeue();
                        __check_and_prepare_file();

                        try
                        {
                            zlog.fileLogStream.WriteLine(
                                zlog.charLogLevel[(int)pk.Level] +
                                pk.When.ToString("[HHmmss:ffffff] ") +
                                pk.Data
                                );
                        }
                        catch (Exception ex)
                        {
                            zlog.lastError = ex.Message;
                        }
                        // Do something with Log Packet, Then continue next packet
                        continue;
                    }
                }
                Thread.Sleep(1);
            }
        }                                              /*}}}*/
예제 #5
0
        /* Thread Method for each logging Role */
        private static void _thread_master()    /*{{{
                                                 */
        {
            zlog.isStartOK_Master = true;       // ok we enter this thread it create success
            zPACKET pk = null;

            while (!zlog.isQuit)
            {
                Thread.Sleep(0);                // Let other process interrupt

                lock (queMaster.SyncRoot)
                {
                    if (queMaster.Count > 0)
                    {
                        pk = (zPACKET)queMaster.Dequeue();
                    }
                    else
                    {
                        pk = null;
                    }
                }
                if (pk != null)
                {
                    // Distribute Log to each thread
                    if (pk.isWriteFile)
                    {
                        lock (queWriteFile.SyncRoot) { queWriteFile.Enqueue(pk); }
                    }
                    if (pk.isWriteConsole)
                    {
                        lock (queWriteConsole.SyncRoot) { queWriteConsole.Enqueue(pk); }
                    }
                    if (pk.isWriteClient)
                    {
                        lock (queWriteClient.SyncRoot) { queWriteClient.Enqueue(pk); }
                    }
                    if (pk.isWriteServer)
                    {
                        lock (queWriteServer.SyncRoot) { queWriteServer.Enqueue(pk); }
                    }

                    // Continue next cycle with let change other process to interrupt
                    continue;
                }

                // Not have any more log queue, Sleep at least 1 microsecond
                Thread.Sleep(1);
            }
        }                                        /*}}}*/
예제 #6
0
        }                                           /*}}}*/

        private static void _thread_write_console() /*{{{
                                                     */
        {
            zlog.isStartOK_WriteConsole = true;
            zlog.debug("zLog Thread_WriteConsole ... Start");

            // Main LOOP for cycle each Log Packet Queue
            while (!zlog.isQuit)
            {
                Thread.Sleep(0);
                lock (queWriteConsole.SyncRoot)
                {
                    if (queWriteConsole.Count > 0)
                    {
                        zPACKET pk = (zPACKET)queWriteConsole.Dequeue();
                        Console.Write(pk.When.ToString("[HHmmss:ffffff] "));
                        Console.WriteLine(pk.Data);
                        continue;
                    }
                }
                Thread.Sleep(1);
            }
        }                                          /*}}}*/