码迷,mamicode.com
首页 > Web开发 > 详细

NLog 通过http保存日志

时间:2016-09-08 09:48:09      阅读:257      评论:0      收藏:0      [点我收藏+]

标签:

from:https://github.com/NLog/NLog/wiki/WebService-target

Example config:

<nlog throwExceptions=‘true‘>
    <targets>
        <target type=‘WebService‘
                name=‘ws‘
                url=‘http://localhost:1234/logme‘
                protocol=‘HttpPost‘
                encoding=‘UTF-8‘   >
            <parameter name=‘param1‘ type=‘System.String‘ layout=‘${message}‘/> 
            <parameter name=‘param2‘ type=‘System.String‘ layout=‘${level}‘/>
        </target>
    </targets>
    <rules>
      <logger name=‘*‘ writeTo=‘ws‘></logger>
    </rules>
</nlog>

Example API controller

public class LogMeController : ApiController
{
    /// <summary>
    /// We need a complex type for modelbinding because 
    /// of content-type: "application/x-www-form-urlencoded" 
    /// in <see cref="WebServiceTarget"/>
    /// </summary>
    public class ComplexType
    {
        public string Param1 { get; set; }
        public string Param2 { get; set; }
    }

    /// <summary>
    /// Post
    /// </summary>
    public void Post([FromBody] ComplexType complexType)
    {
        //do something
    }
}

NLog 通过http保存日志

标签:

原文地址:http://www.cnblogs.com/94cool/p/5851714.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!