Exemplo n.º 1
0
        /// <summary>
        /// To get application log
        /// </summary>
        /// <param name="msg"></param>
        public static string GetLog(LogFileType pLogFileType)
        {
            string retStr = "";

            try
            {
                string filePath = "";
                switch (pLogFileType)
                {
                case LogFileType.Application:
                    filePath = APP_LOG_FILE_PATH;
                    break;

                case LogFileType.Error:
                    filePath = ERROR_LOG_FILE_PATH;
                    break;
                }
                if (System.IO.File.Exists(filePath))
                {
                    System.IO.StreamReader reader = new System.IO.StreamReader(filePath);
                    retStr = reader.ReadToEnd();
                    reader.Close();
                    reader.Dispose();
                    reader = null;
                }
            }
            catch { }
            return(retStr);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Constructor for mailenable
        /// </summary>
        /// <param name="logFileType"></param>
        /// <param name="date"></param>
        /// <param name="time"></param>
        /// <param name="remoteIP"></param>
        /// <param name="agent"></param>
        /// <param name="account"></param>
        /// <param name="serverIPAddress"></param>
        /// <param name="serverPort"></param>
        /// <param name="method"></param>
        /// <param name="uRIStem"></param>
        /// <param name="uRIQuery"></param>
        /// <param name="serverName"></param>
        /// <param name="serverBytes"></param>
        /// <param name="clientBytes"></param>
        /// <param name="userName"></param>
        public LogLine(LogFileType logFileType, string date, string time,
                       string remoteIP, string agent, string account, string serverIPAddress,
                       string serverPort, string method, string uRIStem, string uRIQuery,
                       string serverName, string serverBytes, string clientBytes, string userName)
        {
            if (logFileType != LogFileType.MailEnable)
            {
                throw new ArgumentException();
            }

            string[] dateParts = date.Split('-');
            string[] timeParts = time.Split(':');
            DateTime = new DateTime(Utilities.StrToInt(dateParts[0], 1),
                                    Utilities.StrToInt(dateParts[1], 1), Utilities.StrToInt(dateParts[2], 1),
                                    Utilities.StrToInt(timeParts[0], 1), Utilities.StrToInt(timeParts[1], 1),
                                    Utilities.StrToInt(timeParts[2], 1));

            RemoteIP        = remoteIP;
            Agent           = agent;
            Account         = account;
            ServerIPAddress = serverIPAddress;
            ServerPort      = Utilities.StrToUInt(serverPort, 0);
            Method          = method;
            URIStem         = uRIStem;
            URIQuery        = uRIQuery;
            ServerName      = serverName;
            ServerBytes     = Utilities.StrToUInt(serverBytes, 0);
            ClientBytes     = Utilities.StrToUInt(clientBytes, 0);
            Username        = userName;
        }
Exemplo n.º 3
0
 private void SaveListView(ListView listview)
 {
     try
     {
         LogFileType logFileType = GetFilePrefs();
         if (logFileType != 0)
         {
             StringBuilder strList = new StringBuilder("");
             StreamWriter  sw;
             string        strListFile;
             foreach (AWBLogListener a in listview.Items)
             {
                 strList.AppendLine(a.Output(logFileType));
             }
             strListFile = saveListDialog.FileName;
             sw          = new StreamWriter(strListFile, false, Encoding.UTF8);
             sw.Write(strList);
             sw.Close();
         }
     }
     catch (IOException ex)
     {
         MessageBox.Show(ex.Message, "File error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     catch (Exception ex)
     {
         ErrorHandler.Handle(ex);
     }
 }
Exemplo n.º 4
0
        public LogWatcher(string systemChannelPrefix, LogFileType logFileType, string logPath = null)
        {
            Interval = 250;
            Tick    += OnTick;

            _systemChannelPrefix = systemChannelPrefix;
            _logFileType         = logFileType;

            RootLogsPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), @"EVE\logs");

            if (logPath != null)
            {
                RootLogsPath = logPath;
            }

            if (_logFileType == LogFileType.Game)
            {
                _fileEncoding = Encoding.ASCII;
                _logPath      = RootLogsPath + @"\Gamelogs";
            }
            else
            {
                _fileEncoding = Encoding.Unicode;
                _logPath      = RootLogsPath + @"\Chatlogs";
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Used to clear the application log
        /// </summary>
        /// <param name="pLogFileType"></param>
        /// <returns></returns>
        public static void ClearLog(LogFileType pLogFileType)
        {
            try
            {
                string filePath = "";
                switch (pLogFileType)
                {
                case LogFileType.Application:
                    filePath = APP_LOG_FILE_PATH;
                    break;

                case LogFileType.Error:
                    filePath = ERROR_LOG_FILE_PATH;
                    break;
                }
                try
                {
                    if (System.IO.File.Exists(filePath))
                    {
                        System.IO.StreamWriter writer = new System.IO.StreamWriter(filePath, false);
                        writer.WriteLine("-------------------------------------------------------------------------");
                        writer.WriteLine("Log cleared at " + DateTime.Now.ToString("MM/dd/yyyy hh:mm tt"));
                        writer.WriteLine("-------------------------------------------------------------------------");
                        writer.Flush();
                        writer.Close();
                        writer.Dispose();
                        writer = null;
                    }
                }
                catch { }
            }
            catch { }
        }
Exemplo n.º 6
0
        public string FilenameFor(LogFileType type)
        {
            switch (type)
            {
            case LogFileType.Unknown:
                goto case default;

            case LogFileType.Spots:
                return(_filenameRoot + "smooth.txt");

            case LogFileType.SpotActions:
                return(_filenameRoot + "smooth_spot_actions.txt");

            case LogFileType.BestBreak:
                return(_filenameRoot + "smooth_best_break.txt");

            case LogFileType.Programmes:
                return(_filenameRoot + "smooth_programmes.txt");

            case LogFileType.SmoothConfiguration:
                return(_filenameRoot + "smooth_configuration.json");

            default:
                throw new ArgumentException(nameof(type));
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// LogToFile
        /// </summary>
        /// <param name="logFileType"></param>
        /// <param name="message"></param>
        public static void LogToFile(LogFileType logFileType, string message)
        {
            LoggerGeneral logger = new LoggerGeneral();

            message = DateTime.Now.ToString("HH:mm:ss") + " " + message;
            FormatterGeneral formatter = new FormatterGeneral(message);
            string           logPath   = string.Empty;

            logPath = LogPath + @"\" + DateTime.Now.ToString("yyyyMMdd");// +"_" + DateTime.Now.ToString("HH");
            if (!Directory.Exists(logPath))
            {
                Directory.CreateDirectory(logPath);
            }
            switch (logFileType)
            {
            case LogFileType.TRACE:
                logPath = logPath + @"\TRACE.log";
                break;

            case LogFileType.MESSAGE:
                logPath = logPath + @"\MESSAGE.log";
                break;

            case LogFileType.THREADING:
                logPath = logPath + @"\THREADING.log";
                break;

            default:
                logPath = logPath + @"\EXCEPTION.log";
                break;
            }
            logger.Write(formatter, logPath);
        }
Exemplo n.º 8
0
 public LogFileWriteAction(LogFileWriter file, string @group, LogFileType filetype, byte[] data, int writeNumber)
 {
     File        = file;
     Group       = group;
     FileType    = filetype;
     Data        = data;
     WriteNumber = writeNumber;
 }
Exemplo n.º 9
0
 internal static LogLineParserBase GetLogLineParser(this LogFileType logFileType)
 {
     if (logFileType.Equals(LogFileType.Legacy))
     {
         return(Activator.CreateInstance <LogLineParserLegacy>());
     }
     return(Activator.CreateInstance <LogLineParser>());
 }
Exemplo n.º 10
0
 internal static ClientRunListBase GetClientRunList(this LogFileType logFileType)
 {
     if (logFileType.Equals(LogFileType.Legacy))
     {
         return(Activator.CreateInstance <ClientRunListLegacy>());
     }
     return(Activator.CreateInstance <ClientRunList>());
 }
Exemplo n.º 11
0
 internal static LogLineListBase GetLogLineList(this LogFileType logFileType)
 {
     if (logFileType.Equals(LogFileType.Legacy))
     {
         return((LogLineListBase)Activator.CreateInstance(typeof(LogLineListLegacy), logFileType));
     }
     return((LogLineListBase)Activator.CreateInstance(typeof(LogLineList), logFileType));
 }
Exemplo n.º 12
0
 public LogFileWriteAction(LogFileWriter file, string @group, LogFileType filetype, byte[] data,int writeNumber)
 {
     File = file;
     Group = group;
     FileType = filetype;
     Data = data;
     WriteNumber = writeNumber;
 }
Exemplo n.º 13
0
        public LogGroupStream(LogGroup group, LogFileType type, int size)
        {
            Group = group;
            Type  = type;
            Size  = size;

            AllocateBuffer();
        }
        public static void ReportTestResults(ThreadingType threadingType, LogFileType logFileType)
        {
            Console.WriteLine("-------------------------------------------------------------------------------------------------------------------------------------------------");
            Console.WriteLine();
            Console.WriteLine($"'{threadingType} -> {logFileType}' test FINISHED: {DateTime.Now}");

            if (Parameters.OutputEnvironmentInfoAfterRun)
            {
                EnvironmentInfoUtil.OutputEnvironmentInfo();
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="logFileType">Type of log file</param>
        /// <param name="fileName">Log file name and path</param>
        /// <param name="lastPosition">Last position scanned within the file</param>
        public LogScanner(LogFileType logFileType, string fileName, long lastPosition)
        {
            if (!File.Exists(fileName))
            {
                throw new ArgumentException("File does not exist {0}", fileName);
            }

            _fileName     = fileName;
            FileType      = logFileType;
            _lastPosition = lastPosition;
        }
Exemplo n.º 16
0
 /// <summary>
 /// Create an instance of a log file processor, 
 /// that matches the LogFileType argument.
 /// </summary>
 /// <param name="type"></param>
 /// <returns></returns>
 public static LogFileProcessor Create(LogFileType type)
 {
     switch (type)
     {
         case LogFileType.CombinedLogFormat:
             return new CombinedLogFormatProcessor();
             break;
         default:
             throw new ArgumentException("Unknown log file type.");
     }
 }
Exemplo n.º 17
0
        /// <summary>
        /// Scan the log lines to find client run data and work unit start positions.
        /// </summary>
        /// <param name="logLines">Log lines to scan.</param>
        /// <param name="logFileType">File Type - Legacy or FahClient</param>
        /// <exception cref="ArgumentNullException">Throws if logLines is null.</exception>
        public static List<ClientRun> GetClientRuns(ICollection<LogLine> logLines, LogFileType logFileType)
        {
            if (logLines == null) throw new ArgumentNullException("logLines");

             // Now that we know the LineType for each LogLine, hand off the List
             // of LogLine to the ClientRun List so it can determine the Client
             // and Unit Start Indexes.
             var clientRunList = logFileType.GetClientRunList();
             clientRunList.Build(logLines);

             return clientRunList;
        }
Exemplo n.º 18
0
        /// <summary>
        /// Create an instance of a log file processor,
        /// that matches the LogFileType argument.
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static LogFileProcessor Create(LogFileType type)
        {
            switch (type)
            {
            case LogFileType.CombinedLogFormat:
                return(new CombinedLogFormatProcessor());

                break;

            default:
                throw new ArgumentException("Unknown log file type.");
            }
        }
        public static void Run(LoggingLib lib, LogFileType logFileType, Action <long, int> logAction)
        {
            int numberOfRuns    = Parameters.NumberOfRuns + 1;
            int logsCountPerRun = Parameters.NumberOfLogsPerParallelRun;

            string testCaseName = $"{lib} -> {ThreadingType.MultiThreaded} -> {logFileType}";

            Console.WriteLine();
            Console.WriteLine("-------------------------------------------------------------------------------------------------------------------------------------------------");
            Console.WriteLine($"'{testCaseName}' case STARTED. Number of runs: '{numberOfRuns - 1}', logs per run: '{logsCountPerRun}'");

            long sumOfAllRunsElapsedMs = 0;

            TestCaseStopWatch.Reset();
            TestCaseStopWatch.Start();

            Parallel.For((long)1, numberOfRuns, index =>
            {
                LocalSingleRunStopwatch.Value.Reset();
                LocalSingleRunStopwatch.Value.Start();

                Task task = Task.Factory.StartNew(() =>
                {
                    for (int j = 1; j <= logsCountPerRun; j++)
                    {
                        logAction(index, j);
                    }
                });

                task.Wait();

                LocalSingleRunStopwatch.Value.Stop();

                string runNumber = index < 10 ? $"0{index}" : index.ToString();

                int singleRunTimeInMs = Convert.ToInt32(LocalSingleRunStopwatch.Value.Elapsed.TotalMilliseconds);
                Console.WriteLine($"Run #{runNumber} completed in: {singleRunTimeInMs} ms");

                Interlocked.Add(ref sumOfAllRunsElapsedMs, singleRunTimeInMs);
            });

            TestCaseStopWatch.Stop();

            int totalNumberOfLogsWritten = lib == LoggingLib.NoLoggingLib ? 0 : (numberOfRuns - 1) * logsCountPerRun;

            int totalRunTimeInMs = Convert.ToInt32(TestCaseStopWatch.Elapsed.TotalMilliseconds);

            Console.WriteLine($"'{testCaseName}' case FINISHED. Total logs written: '{totalNumberOfLogsWritten}', whole test case run time: {totalRunTimeInMs} ms, sum of all parallel runs time: {sumOfAllRunsElapsedMs} ms");
        }
Exemplo n.º 20
0
        /// <summary>
        /// Constructor
        /// </summary>
        public LogLine(LogFileType logFileType, string date, string time, string remoteIP)
        {
            if (logFileType != LogFileType.FileZilla)
            {
                throw new ArgumentException();
            }

            string[] dateParts = date.Split('/');
            string[] timeParts = time.Split(':');
            DateTime = new DateTime(Utilities.StrToInt(dateParts[2], 1),
                                    Utilities.StrToInt(dateParts[0], 1), Utilities.StrToInt(dateParts[1], 1),
                                    Utilities.StrToInt(timeParts[0], 1), Utilities.StrToInt(timeParts[1], 1),
                                    Utilities.StrToInt(timeParts[2], 1));
            RemoteIP = remoteIP;
        }
Exemplo n.º 21
0
        private void SaveListView(ListView listview)
        {
            LogFileType logFileType = GetFilePrefs();

            if (logFileType != 0)
            {
                StringBuilder strList = new StringBuilder();

                foreach (AWBLogListener a in listview.Items)
                {
                    strList.AppendLine(a.Output(logFileType));
                }
                Tools.WriteTextFileAbsolutePath(strList.ToString(), saveListDialog.FileName, false);
            }
        }
Exemplo n.º 22
0
        /// <summary>
        /// Scan the log lines to find client run data and work unit start positions.
        /// </summary>
        /// <param name="logLines">Log lines to scan.</param>
        /// <param name="logFileType">File Type - Legacy or FahClient</param>
        /// <exception cref="ArgumentNullException">Throws if logLines is null.</exception>
        public static List <ClientRun> GetClientRuns(ICollection <LogLine> logLines, LogFileType logFileType)
        {
            if (logLines == null)
            {
                throw new ArgumentNullException("logLines");
            }

            // Now that we know the LineType for each LogLine, hand off the List
            // of LogLine to the ClientRun List so it can determine the Client
            // and Unit Start Indexes.
            var clientRunList = logFileType.GetClientRunList();

            clientRunList.Build(logLines);

            return(clientRunList);
        }
Exemplo n.º 23
0
        /// <summary>
        /// Move file to another location and delete from source location.
        /// </summary>
        /// <param name="source"></param>
        private void MoveFile(string source, LogFileType LogType)
        {
            Func <bool> Move = () =>
            {
                Log("Moving file from..", source);
                var    destinationFileName = Path.GetFileNameWithoutExtension(source) + "." + DateTime.Now.ToString("hhmmssfff") + Path.GetExtension(source);
                string destination         = string.Empty;
                if (LogType == LogFileType.Diag)
                {
                    destination = _jobConfig.MailDeliveryProcessArchivePath;
                }
                else
                {
                    destination = _jobConfig.MailFeedbackLoopDeliveryProcessArchivePath;
                }

                if (!Directory.Exists(destination))
                {
                    Directory.CreateDirectory(destination);
                }
                if (File.Exists(source))
                {
                    File.Copy(source, Path.Combine(destination, destinationFileName), true);
                    File.Delete(source);
                    //File.Move(source, destinationFileName);
                    if (LogType == LogFileType.Diag)
                    {
                        _inProcessFileList.Remove(source);
                    }
                    else
                    {
                        _inProcessFeedBackLoopFileList.Remove(source);
                    }
                }
                Log("Moved To..", Path.Combine(destination, destinationFileName));
                return(true);
            };

            try
            {
                Retry.Do <bool>(() => Move(), TimeSpan.FromSeconds(10));
            }
            catch (Exception ex)
            {
                ExceptionHandler.Current.HandleException(ex, DefaultExceptionPolicies.LOG_ONLY_POLICY, values: source);
            }
        }
Exemplo n.º 24
0
        /// <summary>
        /// Move file to another location and delete from source location.
        /// </summary>
        /// <param name="source"></param>
        private static void MoveFile(string source, LogFileType LogType)
        {
            Func <bool> Move = () =>
            {
                Log("Moving file from..", source);
                var    destinationFileName = Path.GetFileNameWithoutExtension(source) + "." + DateTime.Now.ToString("hhmmssfff") + Path.GetExtension(source);
                string destination         = string.Empty;
                if (LogType == LogFileType.Diag)
                {
                    destination = System.Configuration.ConfigurationManager.AppSettings["MAIL_DELIVERY_PROCESS_ARCHIVE_PATH"];
                }
                else
                {
                    destination = System.Configuration.ConfigurationManager.AppSettings["MAIL_FEEDBACKLOOP_DELIVER_PROCESS_ARCHIVE_PATH"];
                }

                if (!Directory.Exists(destination))
                {
                    Directory.CreateDirectory(destination);
                }
                if (File.Exists(source))
                {
                    File.Copy(source, Path.Combine(destination, destinationFileName), true);
                    File.Delete(source);
                    //File.Move(source, destinationFileName);
                    if (LogType == LogFileType.Diag)
                    {
                        inProcessFileList.Remove(source);
                    }
                    else
                    {
                        inProcessFeedBackLoopFileList.Remove(source);
                    }
                }
                Log("Moved To..", Path.Combine(destination, destinationFileName));
                return(true);
            };

            try
            {
                Retry.Do <bool>(() => Move(), TimeSpan.FromSeconds(10));
            }
            catch (Exception ex)
            {
                ExceptionHandler.Current.HandleException(ex, DefaultExceptionPolicies.LOG_ONLY_POLICY, values: source);
            }
        }
Exemplo n.º 25
0
        // Constructor
        public Logger(int blockSize = 100, int blockMax = 100)
        {
            this.blockSize = blockSize;
            this.blockMax  = blockMax;

            blocks = new LogBlock[LOG_BUF_SIZE, blockMax];

            for (int i = 0; i < LOG_BUF_SIZE; i++)
            {
                for (int j = 0; j < blockMax; j++)
                {
                    this.blocks[i, j] = null;
                }
            }

            // 変数の初期化
            logCnt            = 0;
            currentBufferNo   = 0;
            currentBlockNo    = 0;
            currentPos        = 0;
            allocatedBlockNum = new int[LOG_BUF_SIZE];
            fileType          = LogFileType.Text;
            encoding          = Encoding.UTF8; // デフォルトはUTF8

            // 最初に2ブロック確保
            for (int i = 0; i < 2; i++)
            {
                AllocateBlock();
            }

            // Init timer
            InitTimer();

            // デフォルトのファイル名
            logFilePath = @".\default.ulog";

            // レーン情報を登録
            lanes = new Lanes();

            // ログID情報を登録
            logIDs = new LogIDs();

            images = new IconImages();
        }
        public static void Run(LoggingLib lib, LogFileType logFileType, Action <int, int> logAction)
        {
            int numberOfRuns    = Parameters.NumberOfRuns;
            int logsCountPerRun = Parameters.NumberOfLogsPerSyncRun;

            string testCaseName = $"{lib} -> {ThreadingType.SingleThreaded} -> {logFileType}";

            Console.WriteLine();
            Console.WriteLine("-------------------------------------------------------------------------------------------------------------------------------------------------");
            Console.WriteLine($"'{testCaseName}' case STARTED. Number of runs: '{numberOfRuns}', logs per run: '{logsCountPerRun}'");

            long sumOfAllRunsElapsedMs = 0;

            TestCaseStopWatch.Reset();
            TestCaseStopWatch.Start();

            for (int i = 1; i <= numberOfRuns; i++)
            {
                SingleRunStopWatch.Reset();
                SingleRunStopWatch.Start();

                for (int j = 1; j <= logsCountPerRun; j++)
                {
                    logAction(i, j);
                }

                SingleRunStopWatch.Stop();

                string runNumber = i < 10 ? $"0{i}" : i.ToString();

                int singleRunTimeInMs = Convert.ToInt32(SingleRunStopWatch.Elapsed.TotalMilliseconds);
                Console.WriteLine($"Run #{runNumber} completed in: {singleRunTimeInMs} ms");
                sumOfAllRunsElapsedMs += singleRunTimeInMs;
            }

            TestCaseStopWatch.Stop();

            int totalNumberOfLogsWritten = lib == LoggingLib.NoLoggingLib ? 0 : numberOfRuns * logsCountPerRun;

            int totalRunTimeInMs = Convert.ToInt32(TestCaseStopWatch.Elapsed.TotalMilliseconds);

            Console.WriteLine($"'{testCaseName}' case FINISHED. Total logs written: '{totalNumberOfLogsWritten}', whole test case run time: {totalRunTimeInMs} ms, sum of all single runs time: {sumOfAllRunsElapsedMs} ms");
        }
Exemplo n.º 27
0
        public string Output(LogFileType logFileType)
        {
            switch (logFileType)
            {
                case LogFileType.AnnotatedWikiText:
                    string output = "*" + TimeStamp + ": [[" + ArticleTitle + "]]\r\n";
                    if (Skipped)
                        output += "'''Skipped''' by: " + SkippedBy + "\r\n" + "Skip reason: " +
                            SkipReason + "\r\n";
                    return output + ToolTipText + "\r\n";

                case LogFileType.PlainText:
                    return ArticleTitle;

                case LogFileType.WikiText:
                    return "#[[:" + ArticleTitle + "]]";

                default:
                    throw new ArgumentOutOfRangeException("LogFileType");
            }
        }
        public string Output(LogFileType logFileType)
        {
            switch (logFileType)
            {
            case LogFileType.AnnotatedWikiText:
                string output = "*" + TimeStamp + ": [[" + ArticleTitle + "]]\r\n";
                if (Skipped)
                {
                    output += "'''Skipped''' by: " + SkippedBy + "\r\n" + "Skip reason: " +
                              SkipReason + "\r\n";
                }
                return(output + ToolTipText + "\r\n");

            case LogFileType.PlainText:
                return(ArticleTitle);

            case LogFileType.WikiText:
                return("#[[:" + ArticleTitle + "]]");

            default:
                throw new ArgumentOutOfRangeException("logFileType");
            }
        }
Exemplo n.º 29
0
        /// <summary>
        /// Determine log line types and data.
        /// </summary>
        /// <param name="logFilePath">Path to the log file.</param>
        /// <param name="logFileType">File Type - Legacy or FahClient</param>
        /// <exception cref="ArgumentNullException">Throws if logFilePath is null.</exception>
        /// <exception cref="ArgumentException">Throws if logFilePath is empty.</exception>
        public static ICollection <LogLine> GetLogLines(string logFilePath, LogFileType logFileType)
        {
            if (logFilePath == null)
            {
                throw new ArgumentNullException("logFilePath");
            }

            if (logFilePath.Length == 0)
            {
                throw new ArgumentException("Argument 'logFilePath' cannot be an empty string.");
            }

            var logLineList = logFileType.GetLogLineList();

            foreach (string line in File.ReadLines(logFilePath))
            {
                logLineList.Add(line);
            }

            return(logLineList);

            //return GetLogLines(File.ReadAllLines(logFilePath), logFileType);
        }
Exemplo n.º 30
0
        private void WriteLog(string strMessage, LogFileType logfiletype)
        {
            try
            {
                switch (logfiletype)
                {
                case LogFileType.ExceptionLog:
                    File.AppendAllText(LogfilePath + "/" + LogFileName.Split('.')[0] + "_Exception.log", strMessage);
                    break;

                case LogFileType.MainLog:
                    File.AppendAllText(LogfilePath + "/" + LogFileName.Split('.')[0] + "_Main.log", strMessage);
                    break;

                case LogFileType.ValidationLog:
                    File.AppendAllText(LogfilePath + "/" + LogFileName.Split('.')[0] + "_Main.log", strMessage);
                    //File.AppendAllText(LogfilePath + "/" + LogFileName.Split('.')[0] + "_Validation.log", strMessage);
                    break;
                }
            }
            catch (Exception ex)
            {
            }
        }
Exemplo n.º 31
0
        public void LogToFile(LogFileType logType, string logMessage)
        {
            string logDirectory = LogPath + @"\" + DateTime.Today.ToString("yyyyMMdd");
            string filePath     = string.Empty;

            if (!Directory.Exists(logDirectory))
            {
                Directory.CreateDirectory(logDirectory);
                switch (logType)
                {
                case LogFileType.TRACE:
                    filePath = logDirectory + @"\TRACE.0.log";
                    break;

                case LogFileType.MESSAGE:
                    filePath = logDirectory + @"\MESSAGE.0.log";
                    break;

                case LogFileType.EXCEPTION:
                    filePath = logDirectory + @"\EXCEPTION.0.log";
                    break;

                default:
                    filePath = logDirectory + @"\TRACE.0.log";
                    break;
                }
            }
            else
            {
                string[] filePaths = Directory.GetFiles(logDirectory, "*.log");
                if (filePaths.Length == 0)
                {
                    switch (logType)
                    {
                    case LogFileType.TRACE:
                        filePath = logDirectory + @"\TRACE.0.log";
                        break;

                    case LogFileType.MESSAGE:
                        filePath = logDirectory + @"\MESSAGE.0.log";
                        break;

                    case LogFileType.EXCEPTION:
                        filePath = logDirectory + @"\EXCEPTION.0.log";
                        break;

                    default:
                        filePath = logDirectory + @"\TRACE.0.log";
                        break;
                    }
                }
                else
                {
                    List <string> fileList = new List <string>();
                    foreach (string fPath in filePaths)
                    {
                        FileInfo file  = new FileInfo(fPath);
                        string[] parts = file.Name.Split('.');
                        if (parts[0].ToUpper() == logType.ToString().ToUpper())
                        {
                            fileList.Add(fPath);
                        }
                    }

                    int    lastestIndex    = int.MinValue;
                    string lastestFilePath = "";
                    if (fileList.Count <= 0)
                    {
                        filePath = logDirectory + @"\" + logType.ToString().ToUpper() + ".0.log";
                    }
                    else
                    {
                        foreach (string fPath in fileList)
                        {
                            FileInfo file  = new FileInfo(fPath);
                            string[] parts = file.Name.Split('.'); //fPath.Split('.');
                            if (Convert.ToInt32(parts[1]) >= lastestIndex)
                            {
                                lastestIndex    = Convert.ToInt32(parts[1]);
                                lastestFilePath = fPath;
                            }
                        }

                        filePath = lastestFilePath;
                    }

                    if (File.Exists(filePath))
                    {
                        FileInfo lastestFile = new FileInfo(filePath);
                        // check if file size be larger than 5MB then create new one
                        if (((lastestFile.Length / 1024f) / 1024f) > 5)
                        {
                            lastestIndex++;
                            filePath = logDirectory + @"\" + logType.ToString().ToUpper() + "." + lastestIndex + ".log";
                        }
                    }
                }
            }

            logMessage = DateTime.Now.ToString("HH:mm:ss") + " " + logMessage;
            TextWriterTraceListener listener = new TextWriterTraceListener(filePath);

            listener.WriteLine(logMessage);
            listener.Flush();
            listener.Close();
        }
Exemplo n.º 32
0
        /**
         * ログファイルに書き込む
         *
         * @input outputFilePath: 書き込み先のファイルパス
         * @input fileType: 書き込むファイルの種類(テキスト or バイナリ)
         */
        public static void TestWrite1(string outputFilePath, LogFileType fileType)
        {
            // Loggerを作成
            Logger logger = new Logger(1000, 100);

            logger.FileType    = fileType;
            logger.LogFilePath = outputFilePath;
            logger.Encoding    = Encoding.UTF8;

            //-----------------------------------
            // ヘッダー情報を追加
            //-----------------------------------
            logger.AddLogID(1, "id1", UColor.Black);
            logger.AddLogID(2, "id2", UColor.Black);
            logger.AddLogID(3, "id3", UColor.Black);
            logger.AddLogID(4, "id4", UColor.Black);

            logger.AddLane(1, "れーん1", UColor.Black);
            logger.AddLane(2, "れーん2", UColor.Black);
            logger.AddLane(3, "れーん3", UColor.Black);
            logger.AddLane(4, "れーん4", UColor.Black);

            logger.AddImage("あいこん1", @"C:\work\Github\ULoggerCS\Test\Image\icon1.bmp");
            logger.AddImage("あいこん2", @"C:\work\Github\ULoggerCS\Test\Image\icon2.png");

            // ファイルに書き込み
            // ヘッダ書き込みはプログラム開始時のみ、ログ本体書き込みはバッファがいっぱいになるたびに何度も行われる。
            logger.WriteHeader();

            //-----------------------------------
            // 本体部分を追加
            //-----------------------------------

            //----------------------------------------
            // 詳細なしログを追加
            //----------------------------------------
            // エリアを追加
            logger.AddArea("えりあ1", null);

            // ログを追加
            for (int i = 0; i < 1; i++)
            {
                logger.AddLogData(1, LogDataType.Single, 1, "てすと1");
            }

            //----------------------------------------
            // 詳細ありのログを追加
            //----------------------------------------
            // エリアを追加
            logger.AddArea("えりあ1-2", "えりあ1");

            for (int i = 0; i < 1; i++)
            {
                LogDetailTest1 detail = new LogDetailTest1();
                detail.DetailText = "ほげ123";
                logger.AddLogData(1, LogDataType.Single, 1, "てすと2", detail);
            }

            //----------------------------------------
            // 詳細ありのログ2を追加
            //----------------------------------------
            logger.AddArea("えりあ1-3", "えりあ1");
            LogDetailTest2 detail2 = new LogDetailTest2();

            detail2.Init();

            for (int i = 0; i < 1; i++)
            {
                logger.AddLogData(1, LogDataType.Single, 1, "てすと3", detail2);
            }

            // バッファに残ったログを書き込み
            logger.WriteBody(true);

            Console.WriteLine("finished!!");
            // ログを表示
            //logger.DebugPrint();
        }
Exemplo n.º 33
0
 public ApplicationLogger(LogFileType logFileType)
 {
     _logFiletype = logFileType;
     GenerateDefaultFileName();
 }
Exemplo n.º 34
0
        public static void LogToFile(LogFileType logType, string logMessage)
        {
            //string LogPath = Environment.CurrentDirectory;
            var logPath = Path.GetDirectoryName(Environment.GetCommandLineArgs()[0]);//@"C:\VNPT-BHXH";
            var logDirectory = logPath + @"\" + DateTime.Today.ToString("yyyyMMdd");
            string filePath;
            if (!Directory.Exists(logDirectory))
            {
                Directory.CreateDirectory(logDirectory);
                switch (logType)
                {
                    case LogFileType.Trace:
                        filePath = logDirectory + @"\TRACE.0.log";
                        break;
                    case LogFileType.Message:
                        filePath = logDirectory + @"\MESSAGE.0.log";
                        break;
                    case LogFileType.Exception:
                        filePath = logDirectory + @"\EXCEPTION.0.log";
                        break;
                    default:
                        filePath = logDirectory + @"\TRACE.0.log";
                        break;
                }
            }
            else
            {
                var filePaths = Directory.GetFiles(logDirectory, "*.log");
                if (filePaths.Length == 0)
                {
                    switch (logType)
                    {
                        case LogFileType.Trace:
                            filePath = logDirectory + @"\TRACE.0.log";
                            break;
                        case LogFileType.Message:
                            filePath = logDirectory + @"\MESSAGE.0.log";
                            break;
                        case LogFileType.Exception:
                            filePath = logDirectory + @"\EXCEPTION.0.log";
                            break;
                        default:
                            filePath = logDirectory + @"\TRACE.0.log";
                            break;
                    }
                }
                else
                {
                    var fileList = new List<string>();
                    foreach (var fPath in filePaths)
                    {
                        var file = new FileInfo(fPath);
                        var parts = file.Name.Split('.');
                        if (parts[0].ToUpper() == logType.ToString().ToUpper())
                        {
                            fileList.Add(fPath);
                        }
                    }

                    var lastestIndex = int.MinValue;
                    var lastestFilePath = "";
                    if (fileList.Count <= 0)
                    {
                        filePath = logDirectory + @"\" + logType.ToString().ToUpper() + ".0.log";
                    }
                    else
                    {
                        foreach (var fPath in fileList)
                        {
                            var file = new FileInfo(fPath);
                            var parts = file.Name.Split('.'); //fPath.Split('.');
                            if (Convert.ToInt32(parts[1]) >= lastestIndex)
                            {
                                lastestIndex = Convert.ToInt32(parts[1]);
                                lastestFilePath = fPath;
                            }
                        }

                        filePath = lastestFilePath;
                    }

                    if (File.Exists(filePath))
                    {
                        var lastestFile = new FileInfo(filePath);
                        // check if file size be larger than 5MB then create new one
                        if (((lastestFile.Length / 1024f) / 1024f) > 5)
                        {
                            lastestIndex++;
                            filePath = logDirectory + @"\" + logType.ToString().ToUpper() + "." + lastestIndex + ".log";
                        }
                    }
                }
            }

            logMessage = DateTime.Now.ToString("HH:mm:ss") + " " + logMessage;
            var listener = new TextWriterTraceListener(filePath);
            listener.WriteLine(logMessage);
            listener.Flush();
            listener.Close();
        }
Exemplo n.º 35
0
        public static void LogToFile(LogFileType logType, string logMessage)
        {
            //string LogPath = Environment.CurrentDirectory;
            var    logPath      = Path.GetDirectoryName(Environment.GetCommandLineArgs()[0]);//@"C:\VNPT-BHXH";
            var    logDirectory = logPath + @"\" + DateTime.Today.ToString("yyyyMMdd");
            string filePath;

            if (!Directory.Exists(logDirectory))
            {
                Directory.CreateDirectory(logDirectory);
                switch (logType)
                {
                case LogFileType.Trace:
                    filePath = logDirectory + @"\TRACE.0.log";
                    break;

                case LogFileType.Message:
                    filePath = logDirectory + @"\MESSAGE.0.log";
                    break;

                case LogFileType.Exception:
                    filePath = logDirectory + @"\EXCEPTION.0.log";
                    break;

                default:
                    filePath = logDirectory + @"\TRACE.0.log";
                    break;
                }
            }
            else
            {
                var filePaths = Directory.GetFiles(logDirectory, "*.log");
                if (filePaths.Length == 0)
                {
                    switch (logType)
                    {
                    case LogFileType.Trace:
                        filePath = logDirectory + @"\TRACE.0.log";
                        break;

                    case LogFileType.Message:
                        filePath = logDirectory + @"\MESSAGE.0.log";
                        break;

                    case LogFileType.Exception:
                        filePath = logDirectory + @"\EXCEPTION.0.log";
                        break;

                    default:
                        filePath = logDirectory + @"\TRACE.0.log";
                        break;
                    }
                }
                else
                {
                    var fileList = new List <string>();
                    foreach (var fPath in filePaths)
                    {
                        var file  = new FileInfo(fPath);
                        var parts = file.Name.Split('.');
                        if (parts[0].ToUpper() == logType.ToString().ToUpper())
                        {
                            fileList.Add(fPath);
                        }
                    }

                    var lastestIndex    = int.MinValue;
                    var lastestFilePath = "";
                    if (fileList.Count <= 0)
                    {
                        filePath = logDirectory + @"\" + logType.ToString().ToUpper() + ".0.log";
                    }
                    else
                    {
                        foreach (var fPath in fileList)
                        {
                            var file  = new FileInfo(fPath);
                            var parts = file.Name.Split('.'); //fPath.Split('.');
                            if (Convert.ToInt32(parts[1]) >= lastestIndex)
                            {
                                lastestIndex    = Convert.ToInt32(parts[1]);
                                lastestFilePath = fPath;
                            }
                        }

                        filePath = lastestFilePath;
                    }

                    if (File.Exists(filePath))
                    {
                        var lastestFile = new FileInfo(filePath);
                        // check if file size be larger than 5MB then create new one
                        if (((lastestFile.Length / 1024f) / 1024f) > 5)
                        {
                            lastestIndex++;
                            filePath = logDirectory + @"\" + logType.ToString().ToUpper() + "." + lastestIndex + ".log";
                        }
                    }
                }
            }

            logMessage = DateTime.Now.ToString("HH:mm:ss") + " " + logMessage;
            var listener = new TextWriterTraceListener(filePath);

            listener.WriteLine(logMessage);
            listener.Flush();
            listener.Close();
        }
Exemplo n.º 36
0
      /// <summary>
      /// Determine log line types and data.
      /// </summary>
      /// <param name="logFilePath">Path to the log file.</param>
      /// <param name="logFileType">File Type - Legacy or FahClient</param>
      /// <exception cref="ArgumentNullException">Throws if logFilePath is null.</exception>
      /// <exception cref="ArgumentException">Throws if logFilePath is empty.</exception>
      public static ICollection<LogLine> GetLogLines(string logFilePath, LogFileType logFileType)
      {
         if (logFilePath == null) throw new ArgumentNullException("logFilePath");

         if (logFilePath.Length == 0)
         {
            throw new ArgumentException("Argument 'logFilePath' cannot be an empty string.");
         }

         var logLineList = logFileType.GetLogLineList();
         foreach (string line in File.ReadLines(logFilePath))
         {
            logLineList.Add(line);
         }

         return logLineList;

         //return GetLogLines(File.ReadAllLines(logFilePath), logFileType);
      }
Exemplo n.º 37
0
      /// <summary>
      /// Determine log line types and data.
      /// </summary>
      /// <param name="logLines">List of log lines.</param>
      /// <param name="logFileType">File Type - Legacy or FahClient</param>
      /// <exception cref="ArgumentNullException">Throws if logLines is null.</exception>
      public static ICollection<LogLine> GetLogLines(IEnumerable<string> logLines, LogFileType logFileType)
      {
         if (logLines == null) throw new ArgumentNullException("logLines");

         // Need to clear any previous data before adding new range.
         var logLineList = logFileType.GetLogLineList();
         logLineList.AddRange(logLines);

         return logLineList;
      }
Exemplo n.º 38
0
 public LogLineListLegacy(LogFileType logFileType)
     : base(logFileType)
 {
 }
Exemplo n.º 39
0
 public LogLineList(LogFileType logFileType)
     : base(logFileType)
 {
 }