我有点卡住了。我一直在编写一个日志模块,它要求 appender 能够在数据库上执行存储过程来记录我们的信息。我编写了一个自定义 xml 布局,如下所示:
protected override void FormatXml(XmlWriter writer, LoggingEvent loggingEvent)
{
writer.WriteStartElement("LogEntry");
writer.WriteStartElement("DateTime");
writer.WriteString(loggingEvent.TimeStamp.ToLongTimeString());
writer.WriteEndElement();
writer.WriteStartElement("Message");
writer.WriteString(loggingEvent.RenderedMessage);
writer.WriteEndElement();
writer.WriteStartElement("User");
writer.WriteString(loggingEvent.UserName);
writer.WriteEndElement();
writer.WriteStartElement("Process");
writer.WriteString(loggingEvent.ThreadName);
writer.WriteEndElement();
writer.WriteStartElement("Severity");
writer.WriteString(loggingEvent.Level.ToString());
writer.WriteEndElement();
writer.WriteStartElement("Title");
writer.WriteString(loggingEvent.LoggerName);
writer.WriteEndElement();
writer.WriteStartElement("Class");
writer.WriteString(loggingEvent.LocationInformation.ClassName);
writer.WriteEndElement();
writer.WriteStartElement("Filename");
writer.WriteString(loggingEvent.LocationInformation.FileName);
writer.WriteEndElement();
writer.WriteEndElement();
}
所以基本上,我希望 AdoNetAppender 通过这个布局运行日志事件,然后以生成的 Xml 作为参数执行 storproc。IE
EXEC Logging.InsertEntry @XML
不幸的是,周围似乎没有任何例子。
任何帮助将不胜感激。