ProjectArcade

Форк
0
61 строка · 2.1 Кб
1
using System;
2
using System.Globalization;
3
using System.Text;
4

5
namespace DokanNet.Logging
6
{
7
    /// <summary>
8
    /// Extension functions to log messages.
9
    /// </summary>
10
    public static class LoggerExtensions
11
    {
12
        /// <summary>
13
        /// Format a log message.
14
        /// </summary>
15
        /// <param name="message">Message to format.</param>
16
        /// <param name="category">Optional category to add to the log message.</param>
17
        /// <param name="loggerName">Optional log name to at to the log message.</param>
18
        /// <returns>A formated log message.</returns>
19
        public static string FormatMessageForLogging(
20
            this string message,
21
            string category = null,
22
            string loggerName = "")
23
        {
24
            return message.FormatMessageForLogging(false, category, loggerName);
25
        }
26

27
        /// <summary>
28
        /// Format a log message.
29
        /// </summary>
30
        /// <param name="message">Message to format.</param>
31
        /// <param name="addDateTime">If date and time shout be added to the log message.</param>
32
        /// <param name="category">Optional category to add to the log message.</param>
33
        /// <param name="loggerName">Optional log name to at to the log message.</param>
34
        /// <returns>A formated log message.</returns>
35
        public static string FormatMessageForLogging(
36
            this string message,
37
            bool addDateTime = false,
38
            string category = null,
39
            string loggerName = "")
40
        {
41
            var stringBuilder = new StringBuilder();
42
            if (addDateTime)
43
            {
44
                stringBuilder.AppendFormat("{0} - ", DateTime.Now.ToString(CultureInfo.InvariantCulture));
45
            }
46

47
            if (!string.IsNullOrEmpty(loggerName))
48
            {
49
                stringBuilder.Append(loggerName);
50
            }
51

52
            if (!string.IsNullOrEmpty(category))
53
            {
54
                stringBuilder.Append(category+" ");
55
            }
56

57
            stringBuilder.Append(message);
58
            return stringBuilder.ToString();
59
        }
60
    }
61
}

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.