17 static readonly
char[] SEPARATOR = [
'='];
20 readonly
string _format;
21 readonly
string _formatPrefix;
30 _channels = channels ??
throw new ArgumentNullException(nameof(channels));
31 _format = format ??
throw new ArgumentNullException(nameof(format));
32 _formatPrefix = $
"{_format},";
38 if (spec != _format && spec.StartsWith(_formatPrefix) ==
false)
42 var specArray = spec.Split(
',');
43 if (specArray.Length == 0 || specArray[0] != _format)
47 var opts =
new TOptions();
48 foreach (var optionSpec
in specArray.Skip(1))
49 ParseOption(opts, optionSpec);
74 void ParseOption(TOptions options,
string spec)
76 var a = spec.Split(SEPARATOR, 2, StringSplitOptions.None);
77 var key = a.Length >= 1 ? a[0] :
"";
78 var val = a.Length >= 2 ? a[1] :
"";
80 if (
string.IsNullOrWhiteSpace(key))
83 if (key is
"file" or
"trace:file")
84 options.TraceChannel = GetOrCreateChannel(val);
85 if (key is
"file" or
"info:file")
86 options.InfoChannel = GetOrCreateChannel(val);
87 if (key is
"file" or
"warning:file")
88 options.WarningChannel = GetOrCreateChannel(val);
89 if (key is
"file" or
"error:file")
90 options.ErrorChannel = GetOrCreateChannel(val);
91 if (key is
"file" or
"fatal:file")
92 options.FatalChannel = GetOrCreateChannel(val);
104 return _channels.GetOrCreateChannel(spec) ??
throw new InvalidOperationException($
"Cannot find channel for specification '{spec}'.");