Giter Site home page Giter Site logo

le_nlog's Introduction

Logging To Logentries from AppHarbor using NLog

Simple Usage Example


public class HomeController : Controller
{
    private static readonly Logger log = LogManager.GetLogger(typeof(HomeController).Name);

    public ActionResult Index()
    {
        ViewBag.Message = "Welcome to ASP.NET MVC!";

        log.Warn("This is a warning message");

        return View();
    }

    public ActionResult About()
    {
        return View();
    }
}

To configure NLog, you will need to perform the following:

* (1) Obtain your Logentries account key.
* (2) Setup NLog (if you are not already using it).
* (3) Configure the Logentries NLog plugin.

You can obtain your Logentries account key on the Logentries UI, by clicking account in the top left corner

and then display account key on the right.

Logentries NLog Plugin Setup

To install the Logentries Plugin Library, we suggest using Nuget.

The package is found at https://nuget.org/List/Packages/le_nlog

This will also install NLog into your project if it is not already installed.

If you're not using Nuget, the library can be downloaded from:

https://github.com/downloads/logentries/le_nlog/le_nlog.dll

It will need to be referenced in your project.

If you use this option, make sure to install NLog appropriately.

NLog Config

The following configuration needs to be placed in your web.config file directly underneath

the opening <configuration>

<configSections>
  <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
</configSections>
<nlog>
  <extensions>
    <add assembly="le_nlog"/>
  </extensions>
  <targets>
    <target name="logentries" type="Logentries" key="LOGENTRIES_ACCOUNT_KEY" location="LOGENTRIES_LOCATION" 
        debug="true" layout="${date:format=ddd MMM dd} ${time:format=HH:mm:ss} ${date:format=zzz yyyy} ${logger} : ${LEVEL}, ${message, ${exception:format=tostring}"/>
  </targets>
  <rules>
    <logger name="*" minLevel="Info" appendTo="logentries"/>
  </rules>
</nlog>

Replace the value "LOGENTRIES_ACCOUNT_KEY" with your account-key obtained earlier. Also replace the "LOGENTRIES_LOCATION" value. The value you provide here will appear in your Logentries account and will be used to identify your machine and log events. This should be in the following format:

hostname/logname.log

If you would rather create a host and log from your command line instead of the Logentries UI,

you can use the following program:

https://github.com/downloads/logentries/le_log4net/getkey.zip

Run it as follows: getKey.exe --register

Logging Messages

With that done, you are ready to send logs to Logentries.

In each class you wish to log from, enter the following using directive at the top if it is not already there:

using NLog;

Then create this object at class-level:

private static readonly Logger log = LogManager.GetLogger(typeof(NAME_OF_CLASS).Name);

What this does is create a logger with the name of the current class for clarity in the logs.

Now within your code in that class, you can log using NLog as normal and it will log to Logentries.

Example:

log.Debug("Debugging Message");
log.Info("Informational message");
log.Warn("Warning Message");

le_nlog's People

Contributors

marklc-r7 avatar mhinze avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.