วันจันทร์ที่ 1 กรกฎาคม พ.ศ. 2556

Integrate NLog in my MVC 4

use Nuget to get NLog to your MVC
current version is 2.0.1.2 ad 1/7/2555 (d/m/yyyy)

create file NLog.config and input this

<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
    <variable name="appName" value="MOTEWorkflow" />
    <targets>
        <target name="console" xsi:type="ColoredConsole"
          layout="${date:format=HH\:mm\:ss}|${level}|${stacktrace}|${message}" />
        <target name="file" xsi:type="File" fileName="${basedir}/Logs/rrLog.log"
          layout="${date}: ${message}" />
    </targets>
    <rules>
        <logger name="*" minlevel="Info" writeTo="file" />
    </rules>
</nlog>

then when need log use like this

NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
logger.Error( "Test Error" );

this is simple but more configuration and details can be found here.
https://github.com/NLog/NLog/wiki

ไม่มีความคิดเห็น: