Skip to main content

Logging Errors with NLog a .NET Logging Library

NLog is a .NET Logging Library, 

Official Site mentions it as follows,
NLog is a .NET logging library designed with simplicity and flexibility in mind. With NLog you can process diagnostic messages emitted from any .NET language, augment them with contextual information, format them according to your preference and send them to one or more targets.
Using it is very easy. Following steps helps you to get started.
(For Visual Studio 2008, Web Applications)
1. Download and install NLog Library
2. If you are using Visual Studio 2008, follow this step as mentioned in my earlier post, to fix issue with Intellisense.
3. Add reference to NLog.dll.
4. Add the following Entries to web.config


5. Add  following entries to your code behind file
(for C#)
using NLog;
using NLog.Targets;
using NLog.Config;
using NLog.Win32.Targets;

6.  Create a Logger object as below in your code behind file

catch(Exception ex)
{
    Logger errLogger = LogManager.GetLogger("*");
                    errLogger.Debug(ex.Message);
}


7. If you see, i have passed * as an argument to GetLogger method, please refer web.config entry, i have mentioned logger name as *.

8. This will log exceptions to  /Logs/Log.txt

If you encounter any problems then let me know.

Comments

Popular posts from this blog

How to Install Hadoop (2.7.3) on Ubuntu (16.04 LTS)

As I am planning to learn Hadoop, I wanted to install Hadoop (2.7.3) on my Ubuntu (16.04 LTS) and I followed the steps mentioned in the documentation on the Apache Hadoop website. I encountered few problems which are mentioned below, spent some time finding solution to them.

Below are the steps I followed and the description of the error is at the end of this post and also I have mentioned what I missed and what caused these errors.


Step 1. Download Hadoop installation file. For Hadoop 2.7.3 version I used the following link 

http://www.apache.org/dyn/closer.cgi/hadoop/common/hadoop-2.7.3/hadoop-2.7.3-src.tar.gzStep 2. (Assuming you have downloaded the file into /home/<username>/Downloads folder

$ tar zxf hadoop-2.7.3-src.tar.gz
This will extract the files into a folder  "hadoop-2.7.3" .

Step 3. I moved the file to /home/<username> folder (many suggest to move it into /usr/local but I prefer to keep it here, may be once I learn more about linux I might get into tha…

Javascript KeyCode Reference table for Event Handling

The post explains Keyboard event handling using javascript.Javascript events are used to capture user keystrokes. Below is a table of key codes for the keys on a multimedia keyboard. If this table is inconsistent with your own findings, please let me know.

Java Script Code to Find Key code

<script language="JavaScript">
document.onkeydown = checkKeycode
function checkKeycode(e) {
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
alert("keycode: " + keycode);
}
</script>


Key Code Reference Table
Key PressedJavascript Key Codebackspace8tab9enter13shift16ctrl17alt18pause/break19caps lock20escape27page up33page down34end35home36left arrow37up arrow38right arrow39down arrow40insert45delete46048149250351452553654755856957a65b66c67d68

Replacing OpenJDK with Oracle JDK in Ubuntu

You can completely remove the OpenJDK and fresh Install Oracle Java JDK by the following steps:
Remove OpenJDK completely by this command:
sudo apt-get purge openjdk-\*Download the Oracle Java JDKhere.
Note: download appropriate file, for example if your system is x64 Ubuntu (i.e, Debian) the download file is named like this: jdk-8u51-linux-x64.tar.gz
To find which version is your OS, check hereCreate a folder named java in /usr/local/by this command:
sudo mkdir -p /usr/local/javaCopy the Downloaded file in the directory /usr/local/java. To do this, cd into directory where downloaded file is located and use this command for copying that file to /usr/local/java/:
sudo cp -r jdk-8u51-linux-x64.tar.gz /usr/local/java/CD into /usr/local/java/ directory and extract that copied file by using this command:
sudo tar xvzf jdk-8u51-linux-x64.tar.gzAfter extraction you must see a folder named jdk1.8.0_51.Update PATH file by opening /etc/profile file by the command sudo nano /etc/profile and past…