R
Ronald Moolenaar
Hi,
My colleague implemented a class overwriting TextWriter. What he tried
to do was logging to the event logger and logging to console. As you
can see in the code below, the part of 'logging to console' will not
work. However, I could not explain the results when I ran the code.
It seems that when I call the first override, i.e. only one parameter
(a string value), the eventlog contains one new entry as I would
expect. When I call the second or third override (format string and
one/more extra arguments), the eventlog contains two new entries! I
can't explain the second entry in the eventlog.
Is this a bug or can anyone explain this? I am using VS.NET 2003.
public WriterLog : TextWriter
{
private EventLog m_log = new EventLog();
public WriterLog()
{
m_log.Source = "Test";
}
public override void WriterLog(string strValue)
{
m_log.WriteLine(strValue);
base.WriteLine(strValue);
}
public override void WriterLog(string strFormat, object arg0)
{
m_log.WriteLine(String.Format(strFormat, arg0));
base.WriteLine(strFormat, arg0);
}
public override void WriterLog(string strFormat, params object[]
args)
{
m_log.WriteLine(String.Format(strFormat, args));
base.WriteLine(strFormat, args);
}
}
My colleague implemented a class overwriting TextWriter. What he tried
to do was logging to the event logger and logging to console. As you
can see in the code below, the part of 'logging to console' will not
work. However, I could not explain the results when I ran the code.
It seems that when I call the first override, i.e. only one parameter
(a string value), the eventlog contains one new entry as I would
expect. When I call the second or third override (format string and
one/more extra arguments), the eventlog contains two new entries! I
can't explain the second entry in the eventlog.
Is this a bug or can anyone explain this? I am using VS.NET 2003.
public WriterLog : TextWriter
{
private EventLog m_log = new EventLog();
public WriterLog()
{
m_log.Source = "Test";
}
public override void WriterLog(string strValue)
{
m_log.WriteLine(strValue);
base.WriteLine(strValue);
}
public override void WriterLog(string strFormat, object arg0)
{
m_log.WriteLine(String.Format(strFormat, arg0));
base.WriteLine(strFormat, arg0);
}
public override void WriterLog(string strFormat, params object[]
args)
{
m_log.WriteLine(String.Format(strFormat, args));
base.WriteLine(strFormat, args);
}
}