示例#1
0
        public static void Register(Exception exception, LogLevel level = LogLevel.Error)
        {
            var startTime = DateTimeOffset.Now;
            var message   = Regex.Replace(exception.Message, @"\r?\n", " ") + GetPlaceSuffix(exception);
            var count     = ++_counter;
            var logLabel  = $"Exception #{count}";

            LogService.Log($"{logLabel}: {message}", level);
            var fullText = $"{logLabel}\r\n{message}\r\n{ExtendedDump(exception)}";
            var fileName = PathHelper.SafeFileName($"{count.ToString().PadLeft(3, '0')} {message}.txt");

            foreach (var client in Clients)
            {
                try
                {
                    client.PushToWrite(PathHelper.Combine(Kit.DiagnisticsCurrentDirectory, fileName), fullText);
                }
                catch (Exception registerException)
                {
                    Debug.Fail(registerException.ToString());
                    // no throw for register exception
                }
            }

            LogService.Log($"{logLabel} registered at {TimeHelper.FormattedLatency(startTime)}");
        }
示例#2
0
文件: FileClient.cs 项目: chubrik/Kit
        public void PushToReport(string subject, string body, IEnumerable <string> attachmentPaths, string targetDirectory)
        {
            if (attachmentPaths == null)
            {
                throw new ArgumentNullException(nameof(attachmentPaths));
            }

            _reportCounter++;
            var paddedCount = _reportCounter.ToString().PadLeft(3, '0');
            var filePath    = PathHelper.Combine(targetDirectory, PathHelper.SafeFileName($"{paddedCount} {subject}.txt"));

            WriteText(filePath, $"{subject}\r\n\r\n{body}\r\n");
            var attachmentCounter = 0;

            foreach (var attachmentPath in attachmentPaths)
            {
                using (var readStream = OpenRead(attachmentPath))
                    WriteFrom($"{paddedCount}-{++attachmentCounter} {PathHelper.FileName(attachmentPath)}", readStream);
            }
        }