For some special case, you might need to write the log to Windows’ Event Log, To kick start, create a Class so that you can alwiz reuse the code when want to write to Event Log. In my case, I’ve created a Class called EventLogHelper: class EventLogHelper { public static void writeEventLog(String description) { String sSource; String sLog; sSource = “MyService”; sLog = “Application”; if (!EventLog.SourceExists(sSource)) { EventLog.CreateEventSource(sSource, sLog); } [ Read More ]
Here’s a short example on how to read from file and display it to a Label: private void readFile() { String fileName = “D://logs//general.log”; String textLine = “”; System.IO.StreamReader reader; reader= new System.IO.StreamReader(fileName); do { textLine = textLine + reader.ReadLine() + “\r\n”; } while (reader.Peek() != -1); lbl1Ouput.Text = textLine; reader.Close(); } But if the “general.log” is being written at the same time (at other program), then the example above [ Read More ]
Following is the example to send a request via HTTP and then get the response. Here’s how you can test using Visual Studio Express 2010 (1) Create a WebApplication File –> New Project (2) Drag a Label to the Default.aspx (so that we can see the output later) (3) At Default.aspx.cs : using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.IO; using System.Net; using System.Text; [ Read More ]
Following is the example of configuring / using log4net in your C# 3.5 MVC project. (1) Before you start, kindly download the log4net.dll (2) Add the log4net.dll as Reference in your project. Right click your project –> Add Reference –> Browse After that , you will be able to see the dll is added into your project reference: (3) Configure the following in the Web.config (refer to the red higlighted) [ Read More ]