nlog

Adding properties to log message in NLog in .net core

混江龙づ霸主 提交于 2019-11-29 10:45:49
I am using NLog for logging messages in .net core. I have added NLog in StartUp.cs as follows: loggerFactory.AddNLog(); For logging to file, I am using following method: logger.LogInformation("Message"); I want to add custom NLog event properties to my message. But LogInformation() is not allowing me to pass that. How can I do that? truemedia If you want custom layout properties (NLog calls them layout renderers) you can use the EventProperties Layout Renderer . You can simply do this in your code: var logger = LogManager.GetCurrentClassLogger(); var eventInfo = new LogEventInfo(LogLevel.Info,

NLog: How to exclude specific loggers from a specific rule?

折月煮酒 提交于 2019-11-29 10:38:01
问题 In my NLog configuration, I have a catch-all logger but a specific logger I have created is very spammy and I want its output to go to its own file. That part is easy, but the catch-all logger receives the spammy log messages as well. How do I tell the main logger to log everything but to exclude the spammy logger? I'm using NLog 2.0. 回答1: I think something like this is what you want: <logger name="SpammyLogger" minlevel="Off" maxlevel="Trace" final="true" /> <logger name="SpammyLogger"

算法的时间空间复杂度和空间复杂度总结

只谈情不闲聊 提交于 2019-11-29 08:35:07
算法的时间空间复杂度和空间复杂度总结 时间频度 一个算法中的语句执行次数称为语句频度或时间频度。记为T(n)。 如何获得T(n): public static int factorial(int n){ int result = 1; //① if(n == 0 || n == 1){ //② return result; //③ }else{ for(int i = 2;i<=n;i++){ //④ result *= i; //⑤ } return result; //6 } } 上面的这个方法中,①语句执行一次;②虽然是if语句,但判断也需要执行一次;我们通常在计算算法效率时,做最坏打算,因此我们认为if不成立,执行else中的语句,④语句中包含三条语句,各执行了n-1次;⑤语句处于for循环中,执行了n-1次;⑥语句执行一次。因此,T(n)=1+1+4(n-1)+1=n-1 时间复杂度 一般情况下,算法中基本操作重复执行的次数是问题规模n的某个函数,用T(n)表示,若有某个辅助函数f(n),使得当n趋近于无穷大时,T(n)/f(n)的极限值为不等于零的常数,则称f(n)是T(n)的同数量级函数。记作T(n)=O(f(n)),称O(f(n)) 为算法的渐进时间复杂度,简称时间复杂度。 在上面已经提到了求T(n)的方法,现在我们只需要知道怎样通过T(n)求出f(n)

NLog custom LayoutRenderer for scope indentation

半城伤御伤魂 提交于 2019-11-29 07:47:35
can any one provide me of a very sample custom layoutrenderer for nlog ? I want to make indentation while im logging , by example if im calling Method B from Method C the Text log file goes like this : Inside Method C Inside Method B and so on. Stacker here it is: [LayoutRenderer("IndentationLayout")] public sealed class IndentationLayoutRenderer : LayoutRenderer { // Value to substract from stack count private uint _ignore = 12; // Value to pad with. private string _ipadding = "| "; /// <summary>Set the number of (top) stackframes to ignore</summary> public uint Ignore { get { return _ignore;

Problem matching specific NLog logger name

柔情痞子 提交于 2019-11-29 05:16:29
I have two rules configured in NLog.config : <logger name="Model" level="Info" writeTo="modelLog" final="true" /> <logger name="*" minlevel="Debug" writeTo="logFile" /> I am trying to write to the first one, using the following code: LogEventInfo eventInfo = new LogEventInfo(); eventInfo.Level = LogLevel.Info; eventInfo.LoggerName = "Model"; eventInfo.TimeStamp = DateTime.Now; logger.Log(eventInfo); But it keeps falling through to the second rule. I would have thought eventInfo.LoggerName = "Model"; would have sent it straight to the first rule? wageoghe Not at computer now so can't try your

Using NLog with F# Interactive in Visual Studio - Need documentation

拥有回忆 提交于 2019-11-29 05:11:06
I have a need to capture the input and output of F# functions when using F# Interactive. I am able to get NLog to work just fine when the program is run under Visual Studio using F5 or Ctrl-F5. Also the same methods that contain statements to output to the log work just fine and are called when invoked via F# Interactive; just nothing in the log file. I also tried the following with F# Interactive to setup references to NLog and still nothing in the log when run from F# Interactive. #I @"..\packages\NLog.2.0.0.2000\lib\net40" #r @"NLog.dll" And I even found this which led me to try each of

.NetCore使用NLog写入数据库总结

。_饼干妹妹 提交于 2019-11-29 04:35:46
考虑到项目后期添加日志的需求,抽个闲暇时间学习一下使用NLog插件将日志信息写入到数据库中,完整项目见下面; 遇到的问题: 使用NLog写到SQLServer里面的中文显示问号? 解决方法:调整数据库的默认属性排序规则,两种方法: 方法一:手动修改(设置数据库的排序规则) 注意事项:要确定修改的数据库没有被使用,否则会失败! 具体步骤:选中要修改的数据库-->右键-->属性-->弹出数据库属性对话框-->选项-->把排序规则设置成:Chinese_PRC_90_CI_AS-->确定。 方法二:使用代码修改 注意事项:要确定修改的数据库没有被使用,否则会失败!(将数据库连接断开执行这个脚本) 在查询分析其中输入 ALTER DATABASE 数据库名 COLLATE Chinese_PRC_CI_AS 2. 为什么数据库的排序规则会影响到中文的显示? 自己看了一片较少挺详细的: 点我查看哦! 完整测试项目: 请点击这里! 版权声明:本文为博主原创文章,如需转载,请标明出处。 来源: https://www.cnblogs.com/gamecc666/p/11453000.html

Why won't my windows service write to my log file?

℡╲_俬逩灬. 提交于 2019-11-29 01:09:20
I have a windows service and use nlog for logging. Everything works fine when I run from the visual studio ide. The log file updates with no issues. When I install the service, the service runs fine but the log file never updates. I am running under LOCAL SERVICE if that helps. Yes, I have created the logs directory under my application folder. <?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" > <targets> <target name="file" xsi:type="File" fileName="${basedir}/logs/${shortdate}_info.txt"

时间轮算法

孤街浪徒 提交于 2019-11-29 00:21:29
前言 现实开发中有许多的延迟操作,比如定时清理过期数据等,在JDK中自带的Timer或者DelayQueue来实现延迟的功能,但很多开源的中间件中并没有使用Timer或者DelayQueue来实现而是使用基于时间轮算法来实现执行延迟任务功能,例如2.7.0以上的Dubbo基于时间轮实现了,失败定时重发,心跳检测等延迟操作。JDK的Timer和DelayQueue插入和删除操作的平均时间复杂度为O(nlog(n))并不能满足的高性能插入删除的要求,而而基于时间轮可以将插入和删除操作的时间复杂度都降为O(1) 。 实现 时间轮是参考钟表盘来实现,钟表盘上的表针会在固定时间后向前走一格,走完12格后又回到原来位置重复上面流程,时间轮也类似定义了几个格,在固定时间在这几个格上走动。盗图看下结构 如上图,时间轮有多个时间格组成,每个时间格里放置了任务队列,当走到某个时间格时会执行当前时间格里的任务。时间轮的每个时间格用slot表示,时间轮的时间格长度是固定的用wheelLength表示,每个时间格走动的间隔时间也是固定的用tickDuration表示,假设当前指向时间格的第一个位置,要执行一个延迟时间为deadline的任务,那么需要先找到对应的slot将任务加入才能顺利执行,其对应的计算公式:slot = (deadline / tickDuration)%wheelLength

Injecting NLog with Autofac's RegisterGeneric

て烟熏妆下的殇ゞ 提交于 2019-11-28 22:03:13
Note: Updated with suggested improvements, closer but still not quite there! Similar to this question - Passing in the type of the declaring class for NLog using Autofac - I am trying to inject NLog instances into my repository classes. Interface: public interface ILogger<T> where T: class { ... } Implementation: public class NLogger<T> : ILogger<T> where T: class { private readonly Logger _logger; public NLogger() { _logger = LogManager.GetLogger(typeof(T).FullName); } public void Debug(string message) { _logger.Debug(message); } ... } Registered with Autofac as: builder.RegisterGeneric