Ejemplo n.º 1
0
        /// <summary>
        /// Configures the logging of messages by thread.
        /// </summary>
        private static void CreateThreadLogger(string pName, int pThreadID)
        {
            string directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            ArchiveWriter archiveWriter = new ArchiveWriter(directory + @"\logs", pName.ToLower().Replace(' ','-'));
            ThreadWriter threadWriter = new ThreadWriter(archiveWriter, pThreadID);
            FormatWriter formatWriter = new FormatWriter(threadWriter, new DetailFormat());

            Logger.Add(formatWriter);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Constructor
        /// </summary>
        public LoggerControl()
        {
            InitializeComponent();

            FormatWriter format = new FormatWriter(new ListBoxWriter(lbLog), new DetailFormat());

            _threadWriter = new ThreadWriter(format);
            _writer = new MultiWriter
                      {
                          new ContainsWriter(_threadWriter, _MARKER, true), 
                          new ContainsWriter(format, _MARKER, false)
                      };
        }
Ejemplo n.º 3
0
            static ThreadWriter get_thread_writer(System.Threading.Thread thread)
            {
                lock (thread2tws)
                {
                    ThreadWriter tw;
                    if (!thread2tws.TryGetValue(thread, out tw))
                    {
                        try
                        {
                            //cleanup for dead thread logs
                            List<System.Threading.Thread> old_log_keys = (from t in thread2tws.Keys where !t.IsAlive select t).ToList();
                            foreach (System.Threading.Thread t in old_log_keys)
                            {
                                if (t.ThreadState != System.Threading.ThreadState.Stopped)
                                {
                                    thread2tws[t].Error("This thread is detected as not alive. Aborting it...");
                                    t.Abort();
                                }
                                thread2tws[t].Close();
                                thread2tws.Remove(t);
                            }

                            int log_id;
                            if (thread == Log.MainThread)
                                log_id = MAIN_THREAD_LOG_ID;
                            else
                            {
                                log_id = 1;
                                var ids = from x in thread2tws.Keys orderby thread2tws[x].Id select thread2tws[x].Id;
                                foreach (int id in ids)
                                    if (log_id == id) log_id++;
                            }

                            string log_name = Log.EntryAssemblyName;
                            if (log_id < 0)
                                log_name += "_" + Log.TimeMark + ".log";
                            else
                                log_name += "_" + log_id.ToString() + "_" + Log.TimeMark + ".log";

                            tw = new ThreadWriter(log_id, log_name);
                            thread2tws.Add(thread, tw);
                        }
                        catch (Exception e)
                        {
                            Log.Main.Error(e);
                        }
                    }
                    return tw;
                }
            }
Ejemplo n.º 4
0
        private void InitializateFields(Options options)
        {
            int collectorThreadsCount = 1;
            int writerThreadsCount    = 1;

            filePathsStash = new MyConcurrentQueue <string>(collectorThreadsCount, options.ThreadsCount);
            hashSums       = new MyConcurrentQueue <HashFunctionResult>(options.ThreadsCount, writerThreadsCount);
            collector      = new ThreadFileCollector(options.Recursive);
            calculator     = new ThreadHashSumCalculator(options.ThreadsCount, options.Verbose);
            writer         = new ThreadWriter(options.Verbose);

            var connectionFabrica = new ConnectionFabrica();

            connection = connectionFabrica.CreateConnection(options);
        }
Ejemplo n.º 5
0
                static internal ThreadWriter Get(Session session, System.Threading.Thread thread)
                {
                    lock (session.threads2treadWriter)
                    {
                        ThreadWriter tw;
                        if (!session.threads2treadWriter.TryGetValue(thread, out tw))
                        {
                            //cleanup for dead thread logs
                            List <System.Threading.Thread> oldLogThreads = (from t in session.threads2treadWriter.Keys where !t.IsAlive select t).ToList();
                            foreach (System.Threading.Thread t in oldLogThreads)
                            {
                                if (t.ThreadState != System.Threading.ThreadState.Stopped)
                                {
                                    session.threads2treadWriter[t].Error("This thread is detected as not alive. Aborting it...");
                                    t.Abort();
                                }
                                session.threads2treadWriter[t].Close();
                                session.threads2treadWriter.Remove(t);
                            }

                            session.threadWriterCounter++;
                            int logId;
                            if (Log.ReuseThreadLogIndexes)
                            {
                                logId = 1;
                                var ids = session.threads2treadWriter.Values.OrderBy(a => a.Id).Select(a => a.Id);
                                foreach (int id in ids)
                                {
                                    if (logId == id)
                                    {
                                        logId++;
                                    }
                                }
                            }
                            else
                            {
                                logId = session.threadWriterCounter;
                            }

                            tw = new ThreadWriter(session, logId);
                            session.threads2treadWriter.Add(thread, tw);
                        }
                        return(tw);
                    }
                }
                static internal ThreadWriter Get(Session session, System.Threading.Thread thread)
                {
                    lock (session.threadIds2TreadWriter)
                    {
                        ThreadWriter tw;
                        if (!session.threadIds2TreadWriter.TryGetValue(thread.ManagedThreadId, out tw))
                        {
                            //cleanup for dead thread logs
                            List <System.Threading.Thread> oldLogThreads = session.threadIds2TreadWriter.Values.Where(a => !a.Thread.IsAlive).Select(a => a.Thread).ToList();
                            foreach (System.Threading.Thread t in oldLogThreads)
                            {
                                session.threadIds2TreadWriter[t.ManagedThreadId].Close();
                                session.threadIds2TreadWriter.Remove(t.ManagedThreadId);
                            }

                            session.threadWriterCounter++;
                            int logId;
                            if (Log.ReuseThreadLogIndexes)
                            {
                                logId = 1;
                                var ids = session.threadIds2TreadWriter.Values.OrderBy(a => a.Id).Select(a => a.Id);
                                foreach (int id in ids)
                                {
                                    if (logId == id)
                                    {
                                        logId++;
                                    }
                                }
                            }
                            else
                            {
                                logId = session.threadWriterCounter;
                            }

                            tw = new ThreadWriter(session, logId, thread);
                            session.threadIds2TreadWriter.Add(thread.ManagedThreadId, tw);
                        }
                        return(tw);
                    }
                }
Ejemplo n.º 7
0
            static ThreadWriter get_thread_writer(System.Threading.Thread thread)
            {
                lock (thread2tws)
                {
                    ThreadWriter tw;
                    if (!thread2tws.TryGetValue(thread, out tw))
                    {
                        try
                        {
                            //cleanup for dead thread logs
                            List<System.Threading.Thread> old_log_keys = (from t in thread2tws.Keys where !t.IsAlive select t).ToList();
                            foreach (System.Threading.Thread t in old_log_keys)
                            {
                                if (t.ThreadState != System.Threading.ThreadState.Stopped)
                                {
                                    thread2tws[t].Error("This thread is detected as not alive. Aborting it...");
                                    t.Abort();
                                }
                                thread2tws[t].Close();
                                thread2tws.Remove(t);
                            }

                            int log_id;
                            if (thread == Log.MainThread)
                                log_id = MAIN_THREAD_LOG_ID;
                            else
                            {
                                log_id = 1;
                                var ids = from x in thread2tws.Keys orderby thread2tws[x].Id select thread2tws[x].Id;
                                foreach (int id in ids)
                                    if (log_id == id)
                                        log_id++;
                            }

                            string log_name = Log.EntryAssemblyName;
                            if (log_id < 0)
                                log_name += "_" + MainSession.TimeMark + ".log";
                            else
                                log_name += "_" + log_id.ToString() + "_" + MainSession.TimeMark + ".log";

                            tw = new ThreadWriter(log_id, log_name);
                            thread2tws.Add(thread, tw);
                        }
                        catch (Exception e)
                        {
                            Log.Main.Error(e);
                        }
                    }
                    return tw;
                }
            }