5using System.Threading.Tasks;
15 private readonly XmlWriterSettings settings;
16 private StreamWriter file;
17 private readonly
string fileName;
18 private string lastFileName =
null;
19 private readonly
string transform =
null;
20 private readonly
int deleteAfterDays;
38 : this(
ObjectID, FileName, string.Empty, 7)
60 : this(
ObjectID, FileName, string.Empty, DeleteAfterDays)
81 : this(
ObjectID, FileName, Transform, 7)
108 this.fileName = FileName;
109 this.transform = Transform;
110 this.deleteAfterDays = DeleteAfterDays;
112 this.settings =
new XmlWriterSettings
115 ConformanceLevel = ConformanceLevel.Document,
116 Encoding = Encoding.UTF8,
119 NewLineChars =
"\r\n",
120 NewLineHandling = NewLineHandling.Replace,
121 NewLineOnAttributes =
false,
122 OmitXmlDeclaration =
false,
123 WriteEndDocumentOnClose =
true
126 string FolderName = Path.GetDirectoryName(FileName);
128 if (!Directory.Exists(FolderName))
131 Directory.CreateDirectory(FolderName);
142 DateTime TP = DateTime.Now;
143 return TemplateFileName.
144 Replace(
"%YEAR%", TP.Year.ToString(
"D4")).
145 Replace(
"%MONTH%", TP.Month.ToString(
"D2")).
146 Replace(
"%DAY%", TP.Day.ToString(
"D2")).
147 Replace(
"%HOUR%", TP.Hour.ToString(
"D2")).
148 Replace(
"%MINUTE%", TP.Minute.ToString(
"D2")).
149 Replace(
"%SECOND%", TP.Second.ToString(
"D2"));
158 if (File.Exists(FileName))
160 int i = FileName.LastIndexOf(
'.');
170 s = FileName.Insert(i,
" (" + (j++).
ToString() +
")");
172 while (File.Exists(s));
184 if (!(this.lastFileName is
null) && this.lastFileName == s && !(this.file is
null) && this.file.BaseStream.CanWrite)
189 this.
output?.WriteEndElement();
190 this.
output?.WriteEndDocument();
192 this.file?.Dispose();
212 this.file = File.CreateText(s2);
213 this.lastFileName = s;
215 this.output = XmlWriter.Create(this.file, this.settings);
216 this.
output.WriteStartDocument();
218 if (!
string.IsNullOrEmpty(this.transform))
220 if (File.Exists(
this.transform))
226 this.
output.WriteProcessingInstruction(
"xml-stylesheet",
"type=\"text/xsl\" href=\"data:text/xsl;base64," +
227 Convert.ToBase64String(XsltBin) +
"\"");
231 this.
output.WriteProcessingInstruction(
"xml-stylesheet",
"type=\"text/xsl\" href=\"" + this.transform +
"\"");
235 this.
output.WriteProcessingInstruction(
"xml-stylesheet",
"type=\"text/xsl\" href=\"" + this.transform +
"\"");
241 if (this.deleteAfterDays <
int.MaxValue)
243 string FolderName = Path.GetDirectoryName(s);
244 if (
string.IsNullOrEmpty(FolderName))
247 string[] Files = Directory.GetFiles(FolderName,
"*.*");
249 foreach (
string FileName
in Files)
251 if ((DateTime.Now - File.GetLastWriteTime(FileName)).TotalDays >=
this.deleteAfterDays)
255 File.Delete(FileName);
271 base.DisposeOutput();
273 this.file?.Dispose();
Static class managing loading of resources stored as embedded resources or in content files.
static async Task< byte[]> ReadAllBytesAsync(string FileName)
Reads a binary file asynchronously.
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.
static string GetFileName(string TemplateFileName)
Gets the name of a file, given a file name template.
override void DisposeOutput()
Disposes of the current output.
static void MakeUnique(ref string FileName)
Makes a file name unique.
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 Exception(Exception Exception, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, params KeyValuePair< string, object >[] Tags)
Logs an exception. Event type will be determined by the severity of the exception.
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.
delegate string ToString(IElement Element)
Delegate for callback methods that convert an element value to a string.