Exemplo n.º 1
0
        private void AppendLog(LogTypes logType, string section, string method, string text)
        {
            lock (_lock)
            {
                string fullName = "";
                string prefix   = $"{DateTime.Now:dd.MM.yyyy HH:mm:ss} {logType.ToString().PadRight(5)} [{section}]";
                string logStr   = $"{prefix} [{method}] {text}\r\n";
                try
                {
                    string path = string.IsNullOrWhiteSpace(LogfilePath) ? Helper.GetExePath() : LogfilePath;
                    fullName = Path.Combine(path, Constants.DEBUG_LOG);
                    File.AppendAllText(fullName, logStr);
                }
                catch
                {
                    // try to log in program directory

                    /*
                     * string newName = Path.Combine(Helper.GetExePath(), Constants.DEBUG_LOG);
                     * File.AppendAllText(newName, $"{prefix} [AppendLog] Error writing logfile to {fullName}\r\n");
                     * File.AppendAllText(newName, logStr);
                     */
                }
            }
        }
Exemplo n.º 2
0
        public void AppendBinary(byte[] data, BinaryModes mode)
        {
            if (mode == BinaryModes.Send)
            {
                // copy data and set bit 7
                byte[] sendData = new byte[data.Length];
                for (int i = 0; i < data.Length; i++)
                {
                    sendData[i] = (byte)(data[i] | 0x80);
                }
                data = sendData;
            }

            string fullName = "";

            try
            {
                string path = string.IsNullOrWhiteSpace(LogfilePath) ? Helper.GetExePath() : LogfilePath;
                fullName = Path.Combine(path, Constants.BINARY_LOG);
                AppendBinary(fullName, data);
            }
            catch (Exception ex)
            {
                Error(TAG, nameof(AppendBinary), $"Error writing binary data to {fullName}", ex);

                // try to log in program directory
                fullName = Path.Combine(Helper.GetExePath(), Constants.BINARY_LOG);
                AppendBinary(fullName, data);
            }
        }