Hello,
I want to store my logs in a table in oracle, having normal fields, plus an xml field that will contain as many pairs key/value as needed (this will probably evolve). For this I created my own target to store the data into oracle, and creating the xml string about a dictionary that is passed in the parameters. This is working, but shouldn't the context be used for this ? But in my target nothing is available in the context even if I pass things to it previously. Same thing for the log data, I cannot retrieve the log data that can be configured using layout renderer (for example thread id). There is only a limited number of data in the logEvent (message, ...), how can I get the other from my target ? Below are some lines of code for example (and probably there are more efficient way to do that).
[Target("DBX")]
public sealed class DBXTarget : TargetWithLayout {
private string connectionString;
private string query;
private string application;
...
protected override void Write(LogEventInfo logEvent) {
foreach (object o1 in o) {
if (o1 is Hashtable) {
xmlParam = this.CreateXml(Hashtable)o1);
....
this.query = "insert into APPLICATIONLOGS values(SAPPLOG.NEXTVAL, " +
"to_date('" + logEvent.TimeStamp + "','dd.mm.yyyy hh24:mi:ss')" + ", '" +
this.Application + "', '" +
logEvent.Level.Name + "', '" +
logEvent.Message + "', '" +
logEvent.LoggerName + "', '" +
exception + "', '" +
stackTrace + "', '";
this.query += xmlParam + "')";
}
}
Many thanks for your help.
Al