예제 #1
0
        /// <summary>
        /// News the logger job file.
        /// </summary>
        /// <param name="jobType">Type of the job.</param>
        /// <param name="jobName">Name of the job.</param>
        /// <param name="destination">The destination.</param>
        /// <returns>LoggerJob.</returns>
        private WriterJob NewWriterJobFile(JobType jobType, string jobName, object destination)
        {
            if (string.IsNullOrEmpty((string)destination))
            {
                // dont add if there isnt a file name
                return(new WriterJob());
            }

            WriterJob writerJob = new WriterJob()
            {
                JobName             = jobName,
                JobType             = jobType,
                LogFileName         = (string)destination,
                LogFileMaxCount     = CDFMonitor.Instance.Config.AppSettings.LogFileMaxCount,
                LogFileMaxSize      = CDFMonitor.Instance.Config.AppSettings.LogFileMaxSize,
                LogFileMaxSizeBytes = CDFMonitor.Instance.Config.AppSettings.LogFileMaxSize * 1024 * 1024,
                LogFileOverWrite    = CDFMonitor.Instance.Config.AppSettings.LogFileOverWrite,
                LogFileAutoFlush    = CDFMonitor.Instance.Config.AppSettings.LogFileAutoFlush
            };

            writerJob.Writer = new Writer(writerJob);

            if (jobType == JobType.Csv | jobType == JobType.Log)
            {
                AddWriterJob(writerJob);
                if (jobType == JobType.Log)
                {
                    DumpBufferToQueue(writerJob);
                }
            }

            return(writerJob);
        }
예제 #2
0
        /// <summary>
        /// Adds the logger.
        /// </summary>
        /// <param name="jobType">Type of the job.</param>
        /// <param name="jobName">Name of the job.</param>
        /// <param name="param">The param.</param>
        /// <returns>LoggerJob.</returns>
        /// <exception cref="System.NotImplementedException"></exception>
        public WriterJob AddJob(JobType jobType, string jobName, object param = null)
        {
            WriterJob writerJob = new WriterJob();

            // only setup one log of each type for now unless csv and no duplicate names
            Debug.Assert(!_writerJobs.Exists(x => x.JobType == jobType &&
                                             jobType != JobType.Csv ||
                                             x.JobName == jobName));

            switch (jobType)
            {
            case JobType.Console:
            case JobType.Etw:
            case JobType.Gui:
                writerJob = NewWriterJob(jobType, jobName, param);
                break;

            case JobType.Etl:
            case JobType.Csv:
            case JobType.Log:
                writerJob = NewWriterJobFile(jobType, jobName, param);
                break;

            case JobType.Network:
                writerJob = NewWriterJobNet(jobType, jobName, param);
                break;

            default:
                break;
            }

            return(writerJob);
        }
예제 #3
0
        /// <summary>
        /// Removes the job.
        /// </summary>
        /// <param name="writerJob">The logger job.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
        public bool RemoveJob(WriterJob writerJob)
        {
            if (writerJob == null)
            {
                return(true);
            }

            writerJob.Enabled = false;
            if (writerJob.Writer == null)
            {
                Debug.Print("RemoveJob:error:writerJob == null. returning early.");
                return(true);
            }

            if (_writerJobs.Contains(writerJob))
            {
                _writerJobs.Remove(writerJob);
            }

            if (writerJob.Writer.Queue != null)
            {
                writerJob.Writer.Queue.DisableQueue();
                writerJob.Writer.Queue.ClearQueue();

                writerJob.Writer.Queue.Shutdown();
            }

            if (writerJob.Writer.LogManager != null)
            {
                writerJob.Writer.LogManager.StopManagingLogFileServer();
                writerJob.Writer.LogManager.ShutDownLogStream();
            }

            return(true);
        }
예제 #4
0
        /// <summary>
        /// Adds the logger job.
        /// </summary>
        /// <param name="writerJob">The logger job.</param>
        private void AddWriterJob(WriterJob writerJob)
        {
            if (_writerJobs.Exists(x => x.JobName == writerJob.JobName))
            {
                _writerJobs.RemoveAll(x => x.JobName == writerJob.JobName);
            }

            _writerJobs.Add(writerJob);
        }
예제 #5
0
 /// <summary>
 /// Dumps the buffer to queue.
 /// </summary>
 /// <param name="writerJob">The logger job.</param>
 public void DumpBufferToQueue(WriterJob writerJob)
 {
     // catch up with queue
     if (writerJob != null && writerJob.Enabled)
     {
         foreach (string trace in DumpBuffer(_bufferLines))
         {
             writerJob.Writer.Queue.Queue(trace);
         }
     }
 }
예제 #6
0
        /// <summary>
        /// News the logger job net.
        /// </summary>
        /// <param name="jobType">Type of the job.</param>
        /// <param name="jobName">Name of the job.</param>
        /// <param name="param">The param.</param>
        /// <returns>LoggerJob.</returns>
        private WriterJob NewWriterJobNet(JobType jobType, string jobName, object param)
        {
            WriterJob writerJob = new WriterJob()
            {
                JobName  = jobName,
                JobType  = jobType,
                Instance = param
            };

            writerJob.Writer = new Writer(writerJob);
            AddWriterJob(writerJob);

            return(writerJob);
        }
예제 #7
0
        /// <summary>
        /// News the logger job console.
        /// </summary>
        /// <param name="jobType">Type of the job.</param>
        /// <param name="jobName">Name of the job.</param>
        /// <param name="instance">The param.</param>
        /// <returns>LoggerJob.</returns>
        private WriterJob NewWriterJob(JobType jobType, string jobName, object instance = null)
        {
            WriterJob writerJob = new WriterJob()
            {
                JobName  = jobName,
                JobType  = jobType,
                Instance = instance
            };

            writerJob.Writer = new Writer(writerJob);
            AddWriterJob(writerJob);
            DumpBufferToQueue(writerJob);
            return(writerJob);
        }
예제 #8
0
파일: Writer.cs 프로젝트: citrix/CDFMonitor
        //public writer(Job job)
        /// <summary>
        /// Initializes a new instance of the <see cref="Writer" /> class.
        /// </summary>
        /// <param name="job">The job.</param>
        /// <exception cref="System.NotImplementedException"></exception>
        public Writer(WriterJob job)
        {
            _writerJob = job;

            if (string.IsNullOrEmpty(job.JobName))
            {
                CDFMonitor.LogOutputHandler("Fail:writer: logfilename empty. returning.");
                return;
            }

            switch (job.JobType)
            {
            case JobType.Csv:
            case JobType.Log:
                LogManager = new LogManager(job);
                Queue      = new ThreadQueue <string>((data) => { ThreadQueueProcCsv(data); }, job.JobName + "_csvwriter");
                break;

            case JobType.Etl:
                LogManager = new LogManager(job);
                break;

            case JobType.Etw:
                Queue = new ThreadQueue <string>((data) => { ThreadQueueProcEtw(data); }, job.JobName + "_etwwriter");
                break;

            case JobType.Console:
                Queue = new ThreadQueue <string>((data) => { ThreadQueueProcConsole(data); }, job.JobName + "_consolewriter");
                break;

            case JobType.Gui:
                Queue = new ThreadQueue <string>((data) => { ThreadQueueProcGui(data); }, job.JobName + "_guiwriter");
                break;

            case JobType.Network:
                Queue = new ThreadQueue <string>((data) => { ThreadQueueProcUdp(data); }, job.JobName + "_netwriter");
                break;

            case JobType.Unknown:
            default:
                return;
            }

            _writerJob.Enabled = true;

            return;
        }