// adds support for the custom path variable '<appname>' and '<startdate>'
        protected override string FormatFilePath(LogFileInfo logFile, FileLogEntry entry)
        {
            return(Regex.Replace(base.FormatFilePath(logFile, entry), @"<(appname|startdate)(?::([^<>]+))?>", match =>
            {
                var inlineFormat = match.Groups[2].Value;

                switch (match.Groups[1].Value)
                {
                case "appname": return s_appName;

                case "startdate": return GetStartDate(inlineFormat.Length > 0 ? inlineFormat : null, logFile, entry);

                default: throw new InvalidOperationException();
                }
            }));
        }
示例#2
0
文件: FileLog.cs 项目: iAJTin/iEEDID
        private void WriteMessage(string message)
        {
            using (StreamWriter writer = new StreamWriter(Filename, true))
            {
                FileLogEventArgs e = new FileLogEventArgs
                {
                    Writer  = writer,
                    Layout  = Layout,
                    Message = message
                };

                FileLogEntry?.Invoke(this, e);

                if (!e.Handled)
                {
                    writer.Write(message);
                }

                writer.Flush();
            }
        }
 // adds support for the custom path variable '<appname>'
 protected override string FormatFilePath(LogFileInfo logFile, FileLogEntry entry) =>
 base.FormatFilePath(logFile, entry).Replace("<appname>", s_appName);
 // offsets the counter by 1 -> the counter will start at 1
 protected override string GetCounter(string inlineFormat, LogFileInfo logFile, FileLogEntry entry) =>
 (logFile.Counter + 1).ToString(inlineFormat ?? logFile.CounterFormat, CultureInfo.InvariantCulture);
 // returns formatted datetime of when logging started
 protected virtual string GetStartDate(string inlineFormat, LogFileInfo logFile, FileLogEntry entry) =>
 s_startDate.ToString(inlineFormat ?? logFile.DateFormat, CultureInfo.InvariantCulture);