Using Nlog Logging Framework With Vnext In Asp.Net

  ethanmillar        2016-10-26 01:14:53       4,859        0    

In this article, asp.net development company experts will brief you about asp.netVNext and its features. They will also explain how to use NLog Logging framework in Asp.net. Read this article and learn what they want you to understand.

Overview of Asp.Net VNext

The next level of Asp.Net after Asp.Net 5 is Asp.Net VNext. Currently, the code is run in Asp.Net with same CLR as that of desktop apps. There is a need for cloud optimized version of Asp.Net for getting higher throughput with lesser memory use.

Asp.Net will allow programmers to deploy the .Net framework version on the basis of apps. An app having new libraries will not will not break another app of a different version. It is also possible for apps to have the CLR specific to their version. Nuget packages are nothing but cloud optimized libraries and the CLR.


As shown in the above figure, both build 418 and 420 are in the folder 'My packages'. The entire core CLR and the .Net framework are included in the Nuget package. Both of these can be deployed as a Nuget with the app.

Features of VNext

The main features of VNext includes:

  1. It is cloud optimized as well as server optimized.
  2. The concept of dependency injection is out.
  3. Nuget is everything including the runtime.
  4. Both runtime and framework will be deployed side by side with the application.
  5. Asp.Net VNext will run of Mac, Linux as well as Mono.

NLog:

Background for NLog

In the early times, the software was based on the console mostly and no debuggers were there. Tracing messages were written using the printf() command. Now there has been huge enhancement and programmers are using Console.WriteLine() instead of printf() statements. The statements written using Console.WriteLine() are known as tracing statements since their main function is to control the flow of application.

After doing some sort of testing, it was recommended to remove the trace code to improve the performance of application. All tracing code is commented and when required it is re-enabled.  However, this approach required recompilation of the program. After some time, there was need to get the perfect tracing solution so that the programmers could get the following benefits:

  1. Users should have control over the details of different trace messages such as display only warning messages or detailed trace message.
  2. Users should have access to turn the tracing Off or On for separate program components as required without any need to turn the entire application on and Off.
  3. Users should be able to write tracing messages to a system log or a message queue or file or any other output as required.
  4. Users should be able to store important messages in database or send them by mail.

The use of tracing solutions is limited in the era of graphical debuggers. Sometimes, users have only tracing option available to find an error in a critical application.

NLog Overview

NLOgis a library of Asp.Net that allows programmers to include tracing code in an application in a sophisticated manner. NLog helps in specifying rules to control the tracing flow from source to target. A source or a target may be:

  1. Any file
  2. A text console
  3. An email message
  4. Database
  5. A network machine
  6. Message queue based on MSMQ
  7. Event logs etc.

NLog also makes it possible to add additional contextual information to the tracing message that will be sent along to the target. The information include the name of source, stacktrace, the environment variables, process, machine, exceptions etc. Every trace message has an associated log level to describe the severity of the message.

NLog Security Levels:

The following security levels are supported by NLog:

  1. Debug:These include the messages with less detail and these are not very frequent.
  2. Trace:Theses included detailed message that occurs frequency.
  3. Warn:These include the warning messages that are not shown t the user.
  4. Info: These includes the informational messages.
  5. Error: These includes the error messages.
  6. Fatal: These includes fatal message. Usually, the application terminates after such type of message.

NLog and its binaries can be downloaded from its website. It is provided with a graphical installer that allows users to install NLog in a specific state for integration with the Visual Studio including the following:

  1. File Templates configuration.
  2. Intellisence for the config files of NLog
  3. The code snippet.
  4. Dialog integration of add reference dialog.

How to use VNext With NLog:

It is possible to implement Asp.Net VNext with NLog.
Refer to the following steps for using Asp.Net VNext with NLog:

  1. Create a web project in Asp.Net VNext.
  2. Open the file "appsettings.json". It will appear as soon as an application will be created in Asp.Net VNext.
  3. Add the config section of NLog in this file.
  4. Next, add the following references to the project.json file.
        a. Microsoft.Extensions.Logging.NLog
        b. NLog
        c. NLog.Config
  5. Open the appsetting.json file and read the config section of NLog for its configuration.
  6. Deserialize the content from appsetting.json file of NLog config in a class.
  7. Now it is required to inject factory in controller for logging purpose.

Asp.Net VNext has a very little support for NLog. However, implementation of NLog with Asp.Net VNext is easy because of the Microsoft.Extensions.Logging.Nlog that uses an ILogger for logging purposes. Also, there can be many targets for NLogConfig section including database, file etc. In order to use multiple targets, it is required to add settings in app.config file in the nLogConfig section. Similar structure should also be following in the deserialized class.

Experts of asp.net development company have shared basics of asp.netVNext and its features along with the use of NLog Logging framework. In case you have not get any point or have query, ask in comments.

Author Bio

 

Ethan Millar - A Technical Writer at Aegis Softtech, where he leads team to covers a wide range of topics like. He has been working on technical content for 7+ years, acquiring and developing content in areas such as Software, IoT, IT News and Technology Trends.

 

ASP.NET DEVELOPMENT COMPANY  ASP.NET VNEXT  ASP.NET  

       

  RELATED


  0 COMMENT


No comment for this article.



  RANDOM FUN

What would happen if getting on 502 bus