5using System.Threading.Tasks;
15 private readonly XmlWriterSettings settings;
17 private StreamWriter file;
18 private readonly
string transform =
null;
19 private readonly
int deleteAfterDays;
37 : this(
ObjectID, FileName, string.Empty, 7)
59 : this(
ObjectID, FileName, string.Empty, DeleteAfterDays)
80 : this(
ObjectID, FileName, Transform, 7)
108 this.transform = Transform;
109 this.deleteAfterDays = DeleteAfterDays;
111 this.settings =
new XmlWriterSettings
114 ConformanceLevel = ConformanceLevel.Document,
115 Encoding = Encoding.UTF8,
118 NewLineChars =
"\r\n",
119 NewLineHandling = NewLineHandling.Replace,
120 NewLineOnAttributes =
false,
121 OmitXmlDeclaration =
false,
122 WriteEndDocumentOnClose =
true
125 string FolderName = Path.GetDirectoryName(FileName);
127 if (!Directory.Exists(FolderName))
130 Directory.CreateDirectory(FolderName);
139 if (!this.fileSequence.TryGetNewFileName(out
string s))
144 this.
output?.WriteEndElement();
145 this.
output?.WriteEndDocument();
147 this.file?.Dispose();
164 this.file = File.CreateText(s);
166 this.output = XmlWriter.Create(this.file, this.settings);
167 this.
output.WriteStartDocument();
169 if (!
string.IsNullOrEmpty(this.transform))
171 if (File.Exists(
this.transform))
175 byte[] XsltBin = await Runtime.IO.Files.ReadAllBytesAsync(this.transform);
177 this.
output.WriteProcessingInstruction(
"xml-stylesheet",
"type=\"text/xsl\" href=\"data:text/xsl;base64," +
178 Convert.ToBase64String(XsltBin) +
"\"");
182 this.
output.WriteProcessingInstruction(
"xml-stylesheet",
"type=\"text/xsl\" href=\"" + this.transform +
"\"");
186 this.
output.WriteProcessingInstruction(
"xml-stylesheet",
"type=\"text/xsl\" href=\"" + this.transform +
"\"");
192 if (this.deleteAfterDays <
int.MaxValue)
194 string FolderName = Path.GetDirectoryName(s);
196 Runtime.IO.Files.DeleteOldFiles(FolderName, TimeSpan.FromDays(
this.deleteAfterDays), SearchOption.AllDirectories,
true);
205 base.DisposeOutput();
207 this.file?.Dispose();
const string LogNamespace
http://waher.se/Schema/EventOutput.xsd
Outputs sniffed data to an XML file.
XmlFileEventSink(string ObjectID, string FileName, int DeleteAfterDays)
Outputs sniffed data to an XML file.
override void DisposeOutput()
Disposes of the current output.
XmlFileEventSink(string ObjectID, string FileName, string Transform, int DeleteAfterDays)
Outputs sniffed data to an XML file.
XmlFileEventSink(string ObjectID, string FileName)
Outputs sniffed data to an XML file.
override async Task BeforeWrite()
Method is called before writing something to the text file.
XmlFileEventSink(string ObjectID, string FileName, string Transform)
Outputs sniffed data to an XML file.
Outputs sniffed data to an XML writer.
XmlWriter output
XML writer object.
Static class managing the application event log. Applications and services log events on this static ...
static void Informational(string Message, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, string StackTrace, params KeyValuePair< string, object >[] Tags)
Logs an informational event.
virtual string ObjectID
Object ID, used when logging events.
Class that generates a sequence of file names, based on the system time.