nlog

why is CONVERT string to VARBINARY in SQL Server only converting first character?

*爱你&永不变心* 提交于 2019-12-23 08:58:32
问题 I am using NLog to log in my application and as part of that we are logging the customer number, which is a string in C#, and a varbinary(32) in the database. I am using the following SQL code for this specific parameter. The rest of the SQL statement works fine: CONVERT(varbinary(32), @CustNumber) and the following NLog parameter: <parameter name="@CustNumber" layout="${event-context:item=CustNumber}" /> and the following code in C# to add the Nlog parameter: myEvent.Properties.Add(

Functional test based on nlog output

天涯浪子 提交于 2019-12-23 05:41:42
问题 I got some tests which relies on the output from Nlog. I've managed to redirect the output to a variable so I can dive into the string to figured out if all went ok. There must be a better way of doing this but I couldn't manage to find anything. Here's the test and the class being tested: [TestFixture] public class ProcessMessagesFromQueues { private static string StuffLogged; [SetUp] public void Init() { StuffLogged = string.Empty; RedirectNLog(); } private static void RedirectNLog() {

How to write an NLog target using Signalr

时光总嘲笑我的痴心妄想 提交于 2019-12-22 08:29:45
问题 I'm trying to write a target for NLog to send messages out to connected clients using SignalR. Here's what I have now. What I'm wondering is should I be using resolving the ConnectionManager like this -or- somehow obtain a reference to the hub (SignalrTargetHub) and call a SendMessage method on it? Are there performance ramifications for either? [Target("Signalr")] public class SignalrTarget:TargetWithLayout { public SignalR.IConnectionManager ConnectionManager { get; set; } public

NLog dynamically change filename using NLog.config

我的未来我决定 提交于 2019-12-22 06:37:50
问题 How to dynamically change the FileName using a variable from C#? My idea is to create a log file like Log_<UserId_From_DB>_${date:format=yyyy-MM-dd}.log . Any ideas? 回答1: Another option is to use the Global Diagnostic Context - $(GDC): Set the value in C# GlobalDiagnosticsContext.Set("UserId_From_DB","42"); In the config (nlog.config): <target type="file" filename="Log_${gdc:item=UserId_From_DB}_${date:format=yyyy-MM-dd}.log" ..> Please avoid modifying NLog Variables at runtime (See previous

Configure log4net or NLog with XML from code

只谈情不闲聊 提交于 2019-12-21 17:31:26
问题 Recently I have been working on a project where, among other things, we want to provide a centralized configuration system. We are using WCF, Silverlight, C#, etc to create a distributed system of services and clients. One of the things that we will want to configure is logging. Obviously, we can configure log4net or NLog via the app.config or via a separate logging configuration file. We can also configure via code. I wanted to see if it was possible to configure via XML from code. In other

How to use NLog in C++?

删除回忆录丶 提交于 2019-12-21 12:08:28
问题 I have a simple native ++ console application in visual C++. In order to use NLog there is a mixed mode " "NLogC.dll" How can i add "NLogC.dll" to my application And use for logging? Simply how can i use Nlog in a native C++ Application? 回答1: NLog includes a header file ( NLogC.h ) and import library ( NLogC.lib ). Those should be used to use the library. Add the path to the include file (e.g. C:\Program Files (x86)\NLog\.NET Framework 4.0\NLogC\include ) to the include path, either globally

How to set NLog's fileName to the process start date?

本秂侑毒 提交于 2019-12-21 12:07:12
问题 I tried <target name="txtFile" xsi:type="File" fileName="${date:format=yyyy-MM-dd HH-mm-ss}.txt" layout="${longdate} ${level} ${message}"/> but it creates a new file each minute. I realize that there is ${processinfo:property=StartTime} but I couldn't format it. I tried: ${processinfo:property=StartTime:format=yyyy-MM-dd HH-mm-ss} but it doesn't work 回答1: Using the Cached Layout Renderer For a solution that doesn't require code, use the Cached Layout Renderer: <target name="txtFile" xsi:type=

Windows Service with NLog

让人想犯罪 __ 提交于 2019-12-21 05:56:05
问题 I am creating a Windows Service which I want to use NLog with. I want the logs to be written to the install location of the service say something like: PathToInstalledService\Logs\MyLog.txt This is of course going to require administrator priveledges. So my question is, when creating the install for the Service, what account should I use on the ServiceProcessInstaller. I have been currently using LocalService, but this account does not have the required elevation. Thanks. 回答1: During

ASP.NET Core 中的日志记录

百般思念 提交于 2019-12-21 04:03:28
目录 内置日志的使用 使用Nlog 集成ELK 参考 内置日志的使用 Logger 是 asp .net core 的内置 service,所以我们就不需要在ConfigureService里面注册了。同时在asp.net core 2.0版本及以后,系统已经在CreateDefaultBuilder方法里默认配置了输出到Console和Debug窗口的Logger。 .ConfigureLogging(delegate(WebHostBuilderContext hostingContext, ILoggingBuilder logging) { logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging")); logging.AddConsole(); logging.AddDebug(); }) 所以我们可以Controller里面直接注入ILoggerFactory然后再创建具体的Logger。 private readonly ILogger _logger; public HomeController(ILoggerFactory logger) { _logger = logger.CreateLogger<HomeController>(); } 但是还有更好的方式

Unable to set my connectionstring in NLog

廉价感情. 提交于 2019-12-21 03:49:20
问题 The NLog.config file does not set the connection string. <?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" internalLogLevel="Warn" internalLogFile="c:\temp\internal-nlog.txt"> <!-- Load the ASP.NET Core plugin --> <extensions> <add assembly="NLog.Web.AspNetCore" /> </extensions> <variable name="SirNLogDb" value="data source=SQL_MULALLEY;initial catalog=LogFiles;User ID=xxx