PRoConEvents.MULTIbalancer.LogExternal C# (CSharp) Method

LogExternal() private method

private LogExternal ( String msg ) : void
msg String
return void
        private void LogExternal(String msg)
        {
            if (msg == null || ExternalLogSuffix == null) return;
            String entry = "[" + DateTime.Now.ToString("HH:mm:ss") + "] ";
            entry = entry + msg;
            entry = Regex.Replace(entry, @"\^[bni\d]", String.Empty);
            entry = entry.Replace(" [" + GetPluginName() + "]", String.Empty);
            String date = DateTime.Now.ToString("yyyyMMdd");
            String suffix = (String.IsNullOrEmpty(ExternalLogSuffix)) ? "_mb.log" : ExternalLogSuffix;
            String path = Path.Combine(Path.Combine("Logs", fHost + "_" + fPort), date + suffix);

            try {
            if (!Path.IsPathRooted(path)) path = Path.Combine(Directory.GetParent(Application.ExecutablePath).FullName, path);

            // Add newline
            entry = entry + "\n";

            lock (ExternalLogSuffix) { // mutex access to log file
            using (FileStream fs = File.Open(path, FileMode.Append)) {
                Byte[] info = new UTF8Encoding(true).GetBytes(entry);
                fs.Write(info, 0, info.Length);
            }
            }
            } catch (Exception ex) {
            ConsoleError("Unable to append to log file: " + path);
            ConsoleError(ex.ToString());
            }
        }
MULTIbalancer