扩展Nlog Layout Renderer原理、Demo、 工具下载

.NET NLog 详解 (三) - LayoutRender 这期将NLog Git版本指向2005-06-09,NLog v0.9 released。这个时候的代码结构升级为这样: 和上期的版本相比,最明显的莫过于原先的Appender全套更名为Target。这期让我们来关注LayoutRender相关的实现。 LayoutRender 首先LayoutRender 继承自抽象类LayoutRenderer,并且以属性[LayoutRenderer("t 阅读详情
 

我们可以通过修改NLog配置文件来控制日志输出格式,但是有时候我们会有这样的需求:我要把UserID OrderID也记录下来,我们可以像使用${date}${message}一样写${UserID} ${OrderID}么?答案是可以的,只需要写一个扩展。我们讲分析实现原理,给出代码示例,演示一下怎么在程序中应用,并提供一个生成Layout Renderer扩展代码的小工具。

 

Layout Renderer扩展的原理

        作为一个有着良好扩展性的日志组件,我们要实现上述目标也是不必修改NLog源代码的。这很好的符合了面对对象的OCP原则。不过要分析原理还是要从源代码下手,打开“/Log4WF/NLog-1.0/src/NLog/LayoutRenderers”文件夹,这里你可以看到NLog默认的提供的输出标记的实现。

      打开一个ThreadID.cs的文件,我们看一下 :

 1 using  System;
 2 using  System.Text;
 3 using  System.Runtime.InteropServices;
 4
 5 using  NLog.Internal;
 6
 7 namespace  NLog.LayoutRenderers
 8 {
 9    /// <summary>
10    /// The identifier of the current thread.
11    /// </summary>

12    [LayoutRenderer("threadid")]
13    public class ThreadIDLayoutRenderer: LayoutRenderer
14    {
15        /// <summary>
16        /// Returns the estimated number of characters that are needed to
17        /// hold the rendered value for the specified logging event.
18        /// </summary>
19        /// <param name="logEvent">Logging event information.</param>
20        /// <returns>The number of characters.</returns>
21        /// <remarks>
22        /// If the exact number is not known or
23        /// expensive to calculate this function should return a rough estimate
24        /// that's big enough in most cases, but not too big, in order to conserve memory.
25        /// </remarks>

26        protected internal override int GetEstimatedBufferSize(LogEventInfo logEvent)
27        {
28            return 32;
29        }

30
31        /// <summary>
32        /// Renders the current thread identifier and appends it to the specified <see cref="StringBuilder" />.
33        /// </summary>
34        /// <param name="builder">The <see cref="StringBuilder"/> to append the rendered data to.</param>
35        /// <param name="logEvent">Logging event.</param>

36        protected internal override void Append(StringBuilder builder, LogEventInfo logEvent)
37        {
38            builder.Append(ApplyPadding(ThreadIDHelper.Instance.CurrentThreadID.ToString()));
39        }

40    }

41}

42

 这里重载了两个方法:GetEstimatedBufferSize设置缓冲区大小;Append将要记录的内容追加到日志中。

      这也给我们指明了方向,其实我们要做的是两件事情:

1.估计缓冲区大小,这个不难,有些真的是无法估计缓冲区大小的怎么办?打开Message.cs看一下,可以写 logEvent.Message.Length;

2.把要标记所代表的信息追加到日志流中,追加可以很简单的模仿上面的写法,可是到哪里取我们的记录的数据呢?或者说我们要把数据放在哪里可以方便的提取呢?

LogEventInfo这个类代表了要记录的事件信息,除了Message等熟悉之外里面有一个字典类型的Context,可以在这里记录额外的信息。当然了后面我们还要从这里提取出来追加到日志中。看例子,

 

 1 这样LayoutRenderer的扩展也就毫无悬念了,比如我们要写的Query的扩展就会是类似下面这个样子:
 2 using  System;
 3 using  System.Collections.Generic;
 4 using  System.Text;
 5 using  NLog;
 6
 7 namespace  MyTest.NlogLayoutRenderers 
 8 {
 9    [LayoutRenderer("Query")]//注意这里
10    public class QueryLayloutRenderer : LayoutRenderer
11    {
12        protected override int GetEstimatedBufferSize(LogEventInfo logEvent)
13        {
14            return logEvent.Message.Length;//注意这里
15        }

16        protected override void Append(StringBuilder builder, LogEventInfo logEvent)
17        {
18            builder.Append(logEvent.Context["Query"].ToString());//注意这里
19        }

20    }

21}

22
23

在程序中使用自定义扩展

    在NLog如何使用这些自定义的标记呢?

NLog在很多场合做同一件事情都会给我们两个选择,可以用配置文件来做,同样也可以用代码来完成同等的操作。

同样这里也是又两种方式可供选择:

  • 如果只是一个简单的扩展,可以考虑使用代码加载: LayoutRendererFactory.AddLayoutRenderer("UserID", typeof(NLogTest.UserIDLayoutRenderer)); 

完成这样一个预备工作,就可以在后续的代码中使用自定义的UserID标记了。

  • 同样的我们可以把这些自定义的LayoutRenderer的扩展放在一个程序集里面,通过配置NLog的配置文件,可以让NLog在初始化的时候加载这些扩展。这样显然更灵活了。具体配置文件样例如下:
  • <nlog> 
     
    <extensions> 
       
    <add assembly="MyTest"/> 
     
    </extensions> 
     
    <targets> 
       
    <target name="console" type="Console" 
               
    layout="${Query} ${message}"/> 
     
    </targets> 
     
    <rules> 
       
    <logger name="*" minLevel="Info" appendTo="console"/> 
     
    </rules> 
    </nlog> 
    这里有一个细节,extensions配置节必须要写在其它配置节的前面,否则会出错。

 

明白了原理,代码用工具生成吧

程序员也许是最讨厌重复的人群,于是好多人实践重构以消除重复。

  写了一些LayoutRenderer的扩展之后,我们会发现代码绝大多数是相似的,变化的点只有变量名和缓冲区的长度。写一个模板,然后简单的字符串替换生成文件就可以了。没有什么技术含量,只是简化复制粘贴的过程。如果NLog的架构能把这件工作给简化了,那才是真正的简化。

工具包含这样两个东西:

 1 1 .代码模板,需要替换的字符串是@Name @Size
 2 using  System;
 3 using  System.Collections.Generic;
 4 using  System.Text;
 5 using  NLog;
 6
 7 namespace  MyTest.NlogLayoutRenderers
 8 {
 9    [LayoutRenderer("@Name")]
10    public class @NameLayloutRenderer : LayoutRenderer
11    {
12        protected override int GetEstimatedBufferSize(LogEventInfo logEvent)
13        {
14            return @Size;
15        }

16        protected override void Append(StringBuilder builder, LogEventInfo logEvent)
17        {
18            builder.Append(logEvent.Context["@Name"].ToString());
19        }

20    }

21}

22

2.字段列表,每一行包含字段名和字段长度,中间使用TAB隔开

User        50

Session        36

IP        15

Login        24

Online        32

LoginMethod        logEvent.Message.Length

LogoutMethod        logEvent.Message.Length

Library        32

使用的时候只要修改这两个文件就可以了,生成的文件在当前目录的Output文件夹中,文件编码UTF-8。

 

下载地址:NLogTool.rar

 

参考文献: <http://www.nlog-project.org/howto_write_layout_renderer.html>

 

(本文完)

坚强2002和你一起回头再说...
Tag标签: NLog
NLog v4.7.11最新版Demo NLog是一个简单灵活的.NET日志记录类库,v4.7.11最新稳定版Demo 立即下载

相关推荐

日志,NLog日志扩展,大批量日志插入操作源代码

日志,NLog日志扩展,大批量日志插入操作源代码 支持大批量日志写入操作,而不影响应用程序运行。

NLog 配置文件中布局渲染器(layout renderers)

NLog 配置文件中,布局渲染器(layout renderers)是一种机制,用于在日志消息中插入动态内容或格式化信息。它们允许您将变量、属性、日期时间信息等添加到日志消息中,以便更详细地记录和分析日志。布局渲染器是在${}中包含的占位符,会在运行时替换为实际值。

weixin_42098295的博客 1322

别再到处找密钥了!用这3个命令,轻松找回你电脑里的Windows 11专业版激活码

本文详细介绍了三种合法找回Windows 11专业版激活码的方法,包括使用wmic命令提取UEFI固件中的原始密钥、从注册表中获取备份密钥以及通过slmgr查看激活状态。这些方法适用于重装系统后密钥丢失的情况,帮助用户避免使用盗版密钥或重复购买授权。

weixin_33671935的博客 1874

NLog自定义Layout Renderer

更多精彩内容请关注我们长话短说前文《解剖HttpClientFactory,自由扩展HttpMessageHandler》主要讲如何为HttpClientFactory自定义HttpMe...

dotNET跨平台 958

ESP32+LED12864液晶屏实战:手把手教你显示中文与自定义图标(附完整代码)

本文详细介绍了如何使用ESP32单片机驱动带字库的LED12864液晶屏,实现中文显示与自定义图标。从硬件选型、接线方案到驱动编写、字库解析,提供了完整的实战代码与优化技巧,并最终构建了一个智能家居控制面板的完整示例项目。

weixin_29212867的博客 161

ARM6818嵌入式视频播放器:硬解加速与Framebuffer渲染实战

嵌入式Linux音视频系统是智能座舱、工业HMI等场景的核心能力,其本质是软硬协同的实时多媒体处理系统。原理上需打通内核驱动(如VPU硬件编解码、FIMD多图层合成)、用户空间框架(GStreamer pipeline定制、SDL2硬件渲染)与应用层同步机制(PTS/HTS双时钟校准)。技术价值在于显著降低CPU负载(硬解可压至15%以下)、提升启动速度(<1.2s首帧)并保障音画同步精度(±3ms级)。典型应用场景包括车载信息娱乐、边缘AI终端及无X11的工控显示设备。本文基于ARM6818平台,深入VP

weixin_32456485的博客 81

NLog中的布局(Layout)可以使用的内容

  官方网站地址: http://nlog-project.org/wiki/Layout_Renderers

weixin_34187862的博客 1303

Yolov8-pose关键点检测:loss优化 | LRM loss困难样本挖掘,提升难样本、遮挡物等检测精度

LRM loss应用到能够大幅提升pose遮挡物性能

①订阅者答疑群聊服务;②FDE:工业缺陷检测项目;③paper/创新算法指导;④免费提供YOLO创新涨点推荐顾问Skill和AI小怪兽数字分身; 1718

Nlog、Log4Net 的一个小扩展(增加自定义LEVEL)

因公司ELK监控分析日志的需要,需要区分进程运行状态日志以及错误日志,以便能够根据日志级别(level)进行不同策略的预警,而现有的Nlog、Log4Net都没有Process这样的level,故针对这两个日志框架做了一些扩展,实现了自定义PROCESS LEVEL,因代码不多,故直接贴代码,有疑问的或好的建议可以下方评论留言交流,谢谢! NlogExtend.cs:(Nlog的扩展)文件代码内...

weixin_33691817的博客 711

【QT/C++】事件过滤器之基于重写 eventFilter 方法的多种常见应用场景及实现

Qt事件过滤器通过重写eventFilter方法实现多种实用功能:1)鼠标事件处理(点击全选文本、禁用滚轮、悬停提示);2)键盘事件处理(输入内容限制、快捷键提交);3)焦点事件处理(自动弹出下拉框、实时验证);4)绘图事件处理(自定义控件绘制);5)窗口事件处理(防止意外关闭、尺寸限制)。事件过滤器提供非侵入式的事件处理方案,相比传统子类化方式更灵活,通过installEventFilter安装到目标控件即可实现各种交互增强功能。

yuhuasheng1997的博客 1488

YOLOv11改进策略【模型轻量化】| 替换骨干网络 CVPR-2023 FasterNet 高效快速的部分卷积块

本文记录的是基于FasterNet的YOLOv11轻量化改进方法研究。FasterNet的网络结构借鉴 CNN 的设计理念,通过提出的PConv减少推理时的计算和内存成本,同时减少通道数并增加部分比例,降低延迟,并通过后续的PWConv来弥补特征信息可能缺失的问题,提高了准确性。本文在替换骨干网络中配置了原论文中的和六种模型,以满足不同的需求。

Limiiiing的博客 2039

NLog详解

NLog是一个基于.NET平台编写的类库,我们可以使用NLog在应用程序中添加极为完善的跟踪调试代码。NLog是一个简单灵活的.NET日志记录类库。通过使用NLog,我们可以在任何一种.NET语言中输出带有上下文的(contextual information)调试诊断信息,根据喜好配置其表现样式之后发送到一个或多个输出目标(target)中。NLog的API非常类似于log4net,且配置方式非常简单。

liwan09的博客 5338

Tmux学习总结

Tmux 重要概念 使用 Tmux 的时候千万不要去背指令,所有的指令都可以在 .tmux.conf 配置文件中绑定自己顺手的快捷键,也可以配置开启鼠标。 这个是我的配置文件:https://github.com/zuorn/tmux.conf 在Tmux逻辑中,需要分清楚Server > Session > Window > Pane这个大小和层级顺序是极其重要的,直接关系到工作效率: Server:是整个tmux的后台服务。有时候更改配置不生效,就要使用tmux kill-

满目星辰 586

Nlog Layout

Nlog.config <targets> <targettype="Console"name="trace"layout="${message}${newline}${onexception:inner=${newline} *****Error***** ${newline} ${exception:format=toString}${excep...

weixin_30622107的博客 292

rtpengine 项目

rtpengine 项目

原来45的博客 1800

vb 6.0并口开发操作实例

vb6并口开发,简体中文,试例内有inpout32.dll动态链接库

[C#] nlog经典配置文件

<?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" autoReload="true" throwConfigExceptions="true"> <extensions> &.

Eric的博客 1049

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

Nlog详解

NLog是一个基于.NET平台编写的日志记录类库,我们可以使用NLog在应用程序中添加极为完善的跟踪调试代码。可以在任何一种.NET语言中输出带有上下文的(contextual information)调试诊断信息,根据喜好配置其表现样式之后发送到一个或多个输出目标(target)中。官网地址:https://nlog-project.org/文档地址:https://github.com/NLog/NLog/wiki (2)代码实现 (3)运行结果 (2)配置文件 (3)代码实现 (4)运行

李宥的博客 1万+

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

【亲测免费】 NLog.Extensions.Logging 教程

NLog.Extensions.Logging 教程 项目介绍 NLog.Extensions.Logging 是一个开源项目,它提供了一座桥梁,连接了 .NET Core 的 Microsoft.Extensions.Logging 框架与成熟的日志记录解决方案 NLog。通过这个扩展,开发者能够轻松地在基于 .NET Core 或 .NET 5+ 的应用程序中利用 NLog 强大的日志处理能力...

gitblog_00788的博客 1046

Nlog详解---非常详细

Nlog详解

LongtengGensSupreme博客 1万+

NLog条件配置——实现将包含某个特定字符串日志写入指定文件

NLog条件配置,以实现将包含某个特定字符串日志写入指定文件介绍NLog的条件配置如何实现。

bianguanyue的博客 1143

NLog Layout Renderers

转自 https://nlog-project.org/config/?tab=layout-renderers ${cached} - Applies caching to another layout output. ${exception} - Exception information provided through a call to one of the Logger method...

走错路的程序员 1865

NLog文章系列——如何写自定义布局生成器(Layout Renderer)

作者:Jarosław Kowalski &lt;jaak@jkowalski.net&gt; 翻译:CrazyCoder(由衷感谢他的热心!!) 原文:http://www.nlog-project.org/howto_write_layout_renderer.html 更多关于NLog的中文文章,请参考《NLog文章系列》。   为什么需要写自定义布局生成器? 布局生成器能够输出程序的...

weixin_34209406的博客 343

NLog开源框架说明

NLog开源框架说明 NLog是一个简单灵活的.NET日志记录类库。支持的平台也相当广泛,从.net环境到mono再到现在最新的Xamarin均支持。 它允许我们自定义从跟踪消息的来源(source)到记录跟踪信息的目标(target)的规则(rules)。target可以为文件、数据库、网络中的其它计算机(通过TCP或UDP)、基于MSMQ的消息队列、Windows系统日志等。 通过使用NLog...

1653

运行期动态配置 Nlog 日志打印

但是这样一来,我在服务端想要随时的打开和关闭这个设置就尤为麻烦了,尤其是这种配置如果放在 Android App 里面,修改配置还要修改 App 本地的文件,着显然是行不通的。所以目的是放在服务器端的数据库,通过远程的配置来刷新本地 App,这个时候需要从远程的服务器读取配置,在运行时改变 NLog 的行为。至于 starts-with('${message}', 'Tx:') 这样的写法,不是我实现的解析,而是 NLog 自身支持的,需要时,自行去查阅 NLog 的资料。

lee576的专栏 742
上一篇: 我回来了
下一篇: 再战浏览器兼容
坚强2002
博客等级 码龄17年 391粉丝 628原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值