nlog

How to log exceptions with network targets in NLog

好久不见. 提交于 2019-12-12 08:41:26
问题 I am using the NLog logging framework and am trying to get exception and stacktrace information showing up in any UDP logger appliaction, such as Sentinel and Log2Console, but can only get the log message part displayed. Outputting to a file works well as most examples do just that, so the problem revolves around using network targets with NLog. Bonus if a custom format can be applied on inner exceptions and stacktrace, but this is not required. Exception.ToString() would go a long way. Note

Adding method name in NLog

假装没事ソ 提交于 2019-12-12 07:45:06
问题 I am using NLog and following the recommended pattern of having a log declare on each class, for the purpose of being able to track which class/method has written to the log. I do find this very useful to have a bit of a top level 'stack trace' with each log write. My code used to look like this: class SomeClass { private static readonly Logger logger = LogManager.GetCurrentClassLogger(); void DoStuff() { logger.Debug("stuff"); } } I recently had the requirement my single project to write to

Returning a id from database with NLog?

若如初见. 提交于 2019-12-12 03:44:40
问题 While logging exceptions to a table in the SQL Server database the id will increase with each row. I need to return this id to the user while logging with NLog, is this possible? And if so, how? Note : I got only one instance of the NLog Logger class and I do have a custom target (TargetWithLayout) that handle the database communication. 回答1: This was solved by doing a custom target that logges to database and then sets the ID on the parameter sent to the target through NLog. This object can

nlog Logging Map using VB.Net

早过忘川 提交于 2019-12-12 02:41:14
问题 I used nlog in my C# project and it's working as charm, but now I need to use it in VB.NET project and when I convert the code I keep getting this Error: Overload resolution failed because no accessible 'Info' accepts this number of arguments. Overload resolution failed because no accessible 'Debug' accepts this number of arguments. Overload resolution failed because no accessible 'Error' accepts this number of arguments. Overload resolution failed because no accessible 'Fatal' accepts this

Logging in Release Build of Application (C#)

谁说胖子不能爱 提交于 2019-12-12 00:27:51
问题 I've been having a hard time finding information on this subject in both outside research and on StackOverflow/Progammers.StackExchange so I figured I'd ask here. This it mostly a 'best practice' question, but I am interested in the performance repercussions as well. Background: I currently am using the NLog logging framework in a WinForms application with a supporting Windows Service component. I have a lot of tracing log statements throughout the application for my testing which I monitor

.NET core: Hangfire setup with NLog

本小妞迷上赌 提交于 2019-12-11 17:54:49
问题 I have an .NET Core 2 powered API that I would like to add Hangfire to. The project is already using NLog to log to a MySQL database and it works fine, but when I try to setup and use Hangfire I get the following error: Method not found: 'Hangfire.Logging.ILog Hangfire.Logging.LogProvider.GetCurrentClassLogger()'. The Hangfire dashboard works, but I get that error when trying to enqueue my first job like this: BackgroundJob.Enqueue(() => Console.WriteLine("Fire-and-forget")); I have read the

Getting JSNLog to log with NLog

谁都会走 提交于 2019-12-11 16:42:09
问题 I am currently trying to implement a logging system for my ASP.Net application similar to this where Elmah is used to catch all of the .NET Uncaught Exceptions that happen and log them to a SQL Database, with NLog being used for the more lightweight Debug() and Info() calls that will also be logged to a SQL Server. In addition to this I wanted to add JSNLog so that I could send all my Javascript Debug/Info/Errors etc to NLog for storing in the SQL Database too. I have installed Elmah via the

Cannot load nlog.config in Xamarin

心不动则不痛 提交于 2019-12-11 15:27:15
问题 I cannot read nlog.config file in asset folder of android platform NLog.LogManager.Configuration = new XmlLoggingConfiguration("NLog.config"); How to read nlog file and also this file is in android asset. 回答1: You can also make use of Xamarin resource. Put the NLog.config file into the library project, then edit file's properties - change the build action to embedded resource. public static Stream GetEmbeddedResourceStream(Assembly assembly, string resourceFileName) { var resourcePaths =

NLog: Limit Logger Names to Enum or other structure

蹲街弑〆低调 提交于 2019-12-11 14:53:41
问题 I am using NLog for some logging and thanks to these answers: Getting Logger Name into Excel file with NLog https://stackoverflow.com/questions/50123661/nlog-in-c-sharp-with-severity-and-categories?noredirect=1#comment87344565_50123661 I am able to log different types of events (ex: "Thermal", "Database",etc.) to a single file with the logger field showing the type of event. One simply calls for example: NLog.LogManager.GetLogger("Database").Debug("Error writing to DB"); This all works fine

ASP.NET Core Logging with Func() argument

半世苍凉 提交于 2019-12-11 13:49:48
问题 I am using ASP.NET core with NLog, using it as a replacement for the original ASP.NET Core logger with the NLog.Web.AspNetCore nugget package. NLog contains a useful Func() delegate signature that allows to performs arguments evaluation only if the corresponding logging level is enabled: static readonly Logger log = LogManager.GetCurrentClassLogger(); log.Trace(() => request.JsonSerializer.Serialize(body)); I am using ASP.NET with NLog, but it sounds like this feature is not available: