首页 > Web开发 > 详细

NLog 通过http保存日志

时间:2016-09-08 09:48:04      阅读:310      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!