Event log is a central repository for systems information, warning, and errors. Since it is used by most standard applications, I would also recomend it. In this tip/trick, I demonstrate how to configure your app to send messages to it. Read the comments to identify your options.
Add the following on your web.config:
="1.0"="utf-8"
<configuration>
<system.diagnostics>
<trace autoflush="true">
<listeners>
<remove name="Default" />
<clear />
<add name="EventLogListener" type="System.Diagnostics.EventLogTraceListener"
initializeData="TITLE Displayed on source of event log" />
</listeners>
</trace>
<switches>
<add name="General" value="2" />
</switches>
</system.diagnostics>
</configuration>
Example of usages:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Configuration;
using Emailing;
namespace ConsoleVarious
{
class Program
{
static void Main(string[] args)
{
TraceSwitch generalSwitch = new TraceSwitch("General",
"Entire Application");
string odrReportID = "RC";
string odrReportStatusID = "LC";
string msgText = "AMC";
Trace.WriteIf(generalSwitch.TraceVerbose,
string.Format("UpdateODRContactReport method called with {0} {1} {2}.",
odrReportID, odrReportStatusID, msgText));
Trace.WriteIf(generalSwitch.TraceWarning,
string.Format("Update method called {0}.",
"UpdateItNowMothed"));
try
{
int b = 5;
int c = 0;
b = b / c;
}
catch (Exception ex)
{
if (generalSwitch.TraceError)
{
Trace.TraceError("Error Details: {0} Stack: {1}",
ex.Message, ex.StackTrace);
}
}
}
}
}
Technology Developer with 15 years of experience in the IT industry, mostly spent with financial applications and financial business models. Played various roles such as leadership, management, system architect, database modeling and development, middle tier code and development, GUI, Java Script, C#, VB, SQL Server, Sybase Power Design, Red Gate, Scribe, Metastorm, Telerik, Infragistic, Aspose, Silverlight, Visual studio 2010 and others.