nlog

How to get the Stack trace when logging exceptions with NLog?

痞子三分冷 提交于 2019-11-29 20:34:15
When I use the default layout with NLog it only prints the name of the exception. I've been told that the log4jxmlevent layout doesn't prints nothing about the exception. What layout will help me? Example code: try { throw new SystemException(); } catch (Exception ex) { logger.Error("oi", ex); } Default layout output: 2011-01-14 09:14:48.0343|ERROR|ConsoleApplication.Program|oi log4jxmlevent output: <log4j:event logger="ConsoleApplication.Program" level="ERROR" timestamp="1295003776872" thread="9"> <log4j:message>oi</log4j:message> <log4j:NDC /> <log4j:locationInfo class="ConsoleApplication

How do you log errors (Exceptions) in your ASP.NET apps?

混江龙づ霸主 提交于 2019-11-29 20:11:11
I'm looking for the best way to log errors in an ASP.NET application. I want to be able to receive emails when errors occurs in my application, with detailed information about the Exception and the current Request. In my company we used to have our own ErrorMailer, catching everything in the Global.asax Application_Error. It was "Ok" but not very flexible nor configurable. We switched recently to NLog. It's much more configurable, we can define different targets for the errors, filter them, buffer them (not tried yet). It's a very good improvement. But I discovered lately that there's a whole

Logging Generated SQL with EF Core 2 and Nlog

拜拜、爱过 提交于 2019-11-29 20:09:27
问题 I'm getting a little confused with how to log the generated SQL with asp.net core 2 and EntityFrameworkCore 2 and the correct way to go about it. After reading the this link from the MS docs it is saying that I should add during the services configuration in the startup.cs using .UseLoggerFactory(<LoggerFactory>) . However, this seems outdated as when I look to add the logger I get this message; Could someone please tell me the best way to add the logger to log the SQL for debug purposes? I

How do I log a custom field in NLog to database?

谁说我不能喝 提交于 2019-11-29 19:26:29
I currently use NLog on a lot of projects. On some, I log to a database. Here is what I would like to do: CREATE TABLE [dbo].[NLogEntries]( [Id] [bigint] IDENTITY(1,1) NOT NULL, [Origin] [nvarchar](100) NOT NULL, [LogLevel] [nvarchar](20) NOT NULL, [Message] [nvarchar](3600) NOT NULL, [CreatedOn] [datetime] NOT NULL, [OrderId] [int] NULL --Custom field! ) And NLog.config with this target: <target type="Database" name="database" connectionstring="Server=localhost;Database=NLog;Trusted_Connection=True;"> <commandText> INSERT INTO NLogEntries ([Origin], [Message], [LogLevel],[CreatedOn],[OrderId]

How to get NLog to write to database

怎甘沉沦 提交于 2019-11-29 19:06:00
I'm trying to get NLog to log to my database log table but to no avail. I'm sure my connection string is correct because it's the same used elsewhere in my web.config. Writing out to a file works fine, so I know it's not just NLog, but must be something I'm doing wrong. Below is my NLog configuration: <!-- NLOG CONFIGURATION --> <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/Log ${shortdate}.txt" layout="${longdate} ${callsite} ${level}: ${message} $

nlog using the connectionStringName for database logging

﹥>﹥吖頭↗ 提交于 2019-11-29 19:05:35
问题 here is my nlog.config file. I have turned on the throwsException. <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" throwExceptions="true"> <targets> <target type="Database" name="databaseLog" dbProvider="sqlserver" connectionstring="server=.\SQLExpress;database=Movie;integrated security=true"> <commandText> INSERT INTO [Log] ([Description] , [Level] ) VALUES (@Description, @Level ) </commandText> <parameter name="@Description"

大数据最核心的关键技术——32个算法,记得收藏!

自闭症网瘾萝莉.ら 提交于 2019-11-29 16:25:33
奥地利符号计算研究所的Christoph Koutschan博士在自己的页面上发布了一篇文章,提到他做了一个调查,参与者大多数是计算机科学家,他请这些科学家投票选出最重要的算法,以下是这次调查的结果,按照英文名称字母顺序排序。 1、A* 搜索算法— 图形搜索算法——从给定起点到给定终点计算出路径。其中使用了一种启发式的估算,为每个节点估算通过该节点的最佳路径,并以之为各个地点排定次序。算法以得到的次序访问这些节点。因此,A*搜索算法是最佳优先搜索的范例。 2、集束搜索——最佳优先搜索算法的优化。使用启发式函数评估它检查的每个节点的能力。不过,集束搜索只能在每个深度中发现最前面的m个最符合条件的节点,m是固定数字——集束的宽度。 3、二分查找——在线性数组中找特定值的算法,每个步骤去掉一半不符合要求的数据。 4、分支界定算法——在多种最优化问题中寻找特定最优化解决方案的算法,特别是针对离散、组合的最优化。 5、Buchberger算法——一种数学算法,可将其视为针对单变量最大公约数求解的欧几里得算法和线性系统中高斯消元法的泛化。 6、数据压缩——采取特定编码方案,使用更少的字节数(或是其他信息承载单元)对信息编码的过程,又叫来源编码。 7、Diffie-Hellman密钥交换算法——一种加密协议,允许双方在事先不了解对方的情况下,在不安全的通信信道中,共同建立共享密钥

How to log to multiple targets using NLog?

旧时模样 提交于 2019-11-29 12:01:17
问题 I am using NLog and I want to log to RichTextBox and File at the same time. And I want to configure the Logger programmatically, not with xml config file. The following code only logs to the last target (File in this case). Can anybody help? RichTextBoxTarget t1 = new RichTextBoxTarget(); t1.Layout = "${date} ${message}"; t1.ControlName = "rtb_log"; t1.FormName = "MainForm"; NLog.Config.SimpleConfigurator.ConfigureForTargetLogging(t1, LogLevel.Debug); FileTarget t2 = new FileTarget(); t2

Add, enable and disable NLog loggers programmatically

帅比萌擦擦* 提交于 2019-11-29 11:14:02
问题 How can I add, edit, delete, enable, and disable loggers from code for NLog? 回答1: To add: var logTarget = new ... logTarget.Layout = "Your layout format here"; // e.g. "${logger}: ${message} ${exception:format=tostring}"; // specify what gets logged to the above target var loggingRule = new LoggingRule("*", LogLevel.Debug, logTarget); // add target and rule to configuration LogManager.Configuration.AddTarget("targetName", logTarget); LogManager.Configuration.LoggingRules.Add(loggingRule);

Update NLog target filename at runtime

偶尔善良 提交于 2019-11-29 11:02:18
问题 In my application, I work on several thousand of document a day. I'd like, in some cases some logs, one log by document. Then I'd like for a specific target change the output filename (and only the filename) at runtime. Around the web I found how to create a target by programming me I'd like just update a the filename by programming. I tried the code below. The error I receive is "LayoutRender cannot be found 'logDirectory'. Any idea ? Thanks, var target = (FileTarget)LogManager.Configuration