Log4net (1)

In VS 2013, create a new web application project. Go to NuGet, and search for Log4net, and install it in your web project.
image

In your /Bin folder, you should see the log4net dll and xml file
image

And you should see log4net in the Reference
image

(If you cannot see the /bin folder, click “Show All Files” in your project.)
image

Now we want to put the log4net configuration information in a separate file under the application root, called Log4Net.config
Here is the Log4Net.config
image

Open AssemblyInfo.cs and add this line in the end:
image
image

Add a line to web.config in the configSections tag.
image
Add to Startup.cs
image
image

In the caller (ASPX.CS), add these:
image

These log files are created under the root:
image

What the log file looks like:
image

To use Window’s event log to log information, add a new “appender” section to Log4net.config, and change the root section so the EventLogAppender is used for logging.
image

Run the application again, and you will see the logs in Event Log:
image

11/10/2013, 10:05pm

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s