nlog

Can NLog v2 be used with Common.Logging

送分小仙女□ 提交于 2019-12-04 03:04:24
I tried using these together today, and was getting a version mismatch, as it's looking for NLog v1. Does Common.Logging support NLog v2 yet? If not, does anyone know if an assembly version redirect can safely be used? You can simply do assembly redirect in app.config or web.config, and CommonLogging will just work fine with NLog2 by using NLog2 as logging framework: <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="NLog" publicKeyToken="5120e14c03d0593c" culture="neutral" /> <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion

Setting up C# solution with multiple projects using NLog in Visual Studio

醉酒当歌 提交于 2019-12-04 02:30:27
My solution in Visual Studio 2012 currently contains two projects: DLL WPF application (which requires methods of the DLL) Both, the DLL and the WPF application, use NLog for logging. Currently each project contains the NLog DLL itself. Here is what I don't understand: It seems unnecessary to me including the identical NLog DLL in each project. The DLL however shall be reusable in other solutions, i.e. somehow the NLog DLL must be contained in the DLL project. What would be an adequate way of setting up the Visual Studio solution and/or projects? well you need the DLL in all projects where you

How to use NLog for a DLL

微笑、不失礼 提交于 2019-12-03 23:53:31
I am trying to implement a simple log using Nlog Refresh 1.0 for a class Library project. It seems nlog does not create a logfile when it's instantiated from within a dll. Is there some other way around this ? my config file looks like this: <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" throwExceptions="true"> <targets> <target name="file" xsi:type="File" fileName="${basedir}/nlog.txt" /> <target name="console" xsi:type="Console" /> </targets> <rules> <logger name="*" minlevel="Info" writeTo="file" /> <logger name="*" minlevel=

Windows Service with NLog

耗尽温柔 提交于 2019-12-03 20:38:40
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. During installation you should change the permissions of the 'Logs' directory to allow your service account to write files.

Buffering log messages in NLog and manually flushes them to target

 ̄綄美尐妖づ 提交于 2019-12-03 19:56:00
问题 I am trying to log via the NLog MailTarget. It works just fine, but i wanted to wrap the mailtarget with the BufferedTargetWrapper to buffer the log messages until a predefined codepoint, where i want to manually flush the buffer and send the previusly buffered log messages by an single mail (like defined in the mail target). If I define a FlushTimeout or the BufferSize of the BufferedTargetWrapper everything still works just fine as supposed. But if the FlushTimeout and the BufferSize is not

在asp.net core中使用NLog

爱⌒轻易说出口 提交于 2019-12-03 14:23:22
第一步:nuget 引入 NLog.Web.AspNetCore 4.5+ 第二步:放入nlog.config <?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"> <!-- 加载ASP.NET Core插件 --> <extensions> <add assembly="NLog.Web.AspNetCore"/> </extensions> <!-- 输出目的地 --> <targets> <!-- 输出到文件,这个文件记录所有日志 --> <target xsi:type="File" name="allfile" fileName="c:\temp\nlog-all-${shortdate}.log" layout="${longdate}|${event-properties:item=EventId.Id}|${logger}|${uppercase:

NLog - Write NULL to optional database column

可紊 提交于 2019-12-03 13:14:21
I am using NLog for logging in an ASP.Net application and making use of the database target with Microsoft Sql Server. I have some logging parameters that are optional and not always specified. I would like these to be written as null when they are not provided, however NLog seems to always write them as empty strings. Is there a way to configure it to write null as the default? Ref: https://github.com/nlog/NLog/wiki/Database-target [EDIT] Maybe a more obvious solution than what I propose below would be to change from using an INSERT statement to using a database procedure to log. If you use a

Unable to set my connectionstring in NLog

时间秒杀一切 提交于 2019-12-03 11:49:39
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;Password=yyy;"> </variable> <!-- providerName="System.Data.SqlClient"--> <!-- the targets to write to -

Cannot load Exchange powershell snap-in: The type initializer for 'Microsoft.Exchange.Data.Directory.Globals' threw an exception

╄→尐↘猪︶ㄣ 提交于 2019-12-03 11:23:14
I have the following code that creates a PowerShell runspace with the Exchange 2010 snap in loaded. Dim runspaceConfig = RunspaceConfiguration.Create() Dim snapInException As PSSnapInException = Nothing runspaceConfig.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.E2010", snapInException) Dim runspace = RunspaceFactory.CreateRunspace(runspaceConfig) runspace.Open() Since installing Visual Studio 2012 I started getting the following error when executing the line that adds the snap-in to the runspace config. System.Management.Automation.Runspaces.PSSnapInException occurred HResult=

Registering NLog ILogger with Simple Injector

╄→гoц情女王★ 提交于 2019-12-03 11:07:29
Is there any way I can get the context so I can retrieve the loggerName and use LogManager.GetLogger(loggerName) instead of LogManager.GetCurrentClassLogger() ? I noticed container.RegisterConditional() has access to the context. Also, I want to avoid solutions like SimpleLogging.NLog for now. Finally, I am willing to accept this is not the right approach. BTW, AOP is an option that I've already explored ( Is it a good practice to have logger as a singleton? ). Note: I am aware that GetCurrentClassLogger() gets the same information I'd retrieve with .NET reflection. using NLog; using