-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathLogFileNameFormatterBase.cs
55 lines (32 loc) · 1.31 KB
/
LogFileNameFormatterBase.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System;
using System.Text;
namespace Gsemac.IO.Logging {
public abstract class LogFileNameFormatterBase :
ILogFileNameFormatter {
// Public members
public string Name { get; set; } = "debug";
public string FileExtension { get; set; } = ".log";
public virtual string GetFileName() {
StringBuilder sb = new StringBuilder();
sb.Append(Name);
if (!string.IsNullOrWhiteSpace(FileExtension) && !Name.EndsWith(FileExtension, StringComparison.OrdinalIgnoreCase)) {
if (!FileExtension.StartsWith("."))
sb.Append(".");
sb.Append(FileExtension);
}
return sb.ToString();
}
// Protected members
public LogFileNameFormatterBase() { }
public LogFileNameFormatterBase(string fileName) {
if (fileName is null)
throw new ArgumentNullException(nameof(fileName));
if (string.IsNullOrWhiteSpace(fileName))
throw new ArgumentException(nameof(fileName));
Name = fileName;
string fileExtension = PathUtilities.GetFileExtension(fileName);
if (!string.IsNullOrWhiteSpace(fileExtension))
FileExtension = fileExtension;
}
}
}