我正在尝试将当前页面URL记录为NLog布局的一部分.我已经搜索了NLog布局变量并且没有提出任何结果.
有谁知道如何将当前页面URL作为布局的变量?也可以只提取域名,以便可以在EventLog源属性中使用它?
当我取消支持nlog的数据库时,没有任何内容被记录,似乎NLog吞下了这个问题.有没有办法将它配置为引发和异常,或者至少登录一个记录失败的文本文件?
这是我的配置:
<?xml version="1.0" ?>
<nlog autoReload="true" throwExceptions="true" internalLogFile="${basedir}/App_Data/nlog.txt" internalLogLevel="Debug"
internalLogToConsole="true">
<targets>
<!--Useful for debugging-->
<target name="consolelog" type="ColoredConsole"
layout="${date:format=HH\:mm\:ss}|${level}|${stacktrace}|${message}" />
<target name="databaselog" type="Database">
<dbProvider>System.Data.SqlClient</dbProvider>
<!-- database connection parameters -->
<!-- alternatively you could provide a single 'connectionstring' parameter -->
<connectionString>Data Source=.\SQLEXPRESSZ;Initial Catalog=aspnetdb;Integrated Security=SSPI</connectionString>
<commandText>
insert into NLog_Error ([time_stamp],[level],[host],[type],[source],[logger],[message],[stacktrace],[allxml]) values(@time_stamp,@level,@host,@type,@source,@logger,@message,@stacktrace,@allxml);
</commandText>
<parameter name="@time_stamp" layout="${utc_date}" />
<parameter name="@level" layout="${level}" />
<parameter name="@host" layout="${machinename}" />
<parameter name="@type" layout="${exception:format=type}" />
<parameter name="@source" layout="${callsite:className=true:fileName=false:includeSourcePath=false:methodName=false}" />
<parameter name="@logger" layout="${logger}" />
<parameter name="@message" layout="${message}" />
<parameter name="@stacktrace" …Run Code Online (Sandbox Code Playgroud) 我在特定的DLL中使用Nlog进行日志记录.然后将DLL用于另一个应用程序(使用它动态加载System.Reflection.Assembly.LoadFrom(path + a.dll)).我手动将Nlog.dll和Nlog.config文件放在Path文件夹中,应用程序正常执行,但它不记录任何消息.
但是,当我继续并在应用程序目录(\bin\debug\)中手动放置Nlog.config文件时,会记录消息.
有人可以让我知道如何将Nlog.Config的搜索位置指向不同的目录(d:\dev)\bin\debug\.
c# configuration nlog configuration-files nlog-configuration
.net MAUI 最近在其最新版本之一中删除了日志记录。现在有什么替代方案以及应该如何实施?已经在网上查遍了,但找不到任何实现的日志架构的示例。尝试过log4net,NLog但最终没有成功设置其中任何一个。在线有 0 个用于在 MAUI 上设置任何日志记录的示例。
另外,在 MauiProgram 中看到了builder.Services.AddLogging()和builder.Logging.Services,它应该与依赖注入一起使用,但也找不到该实现的任何 Maui 示例。
现在应该如何在 MAUI 中设置基本日志记录?
我有一个Web项目(ASP.NET MVC 4项目),它有许多配置存储在Web.Config和NLog.config文件中.
我有几个发布配置文件PublishProfile1,PublishProfile2等.当使用发布配置文件将我的Web项目部署到服务器时,我想在部署后更改两个配置文件中的一些配置(Web.config中的一些应用程序设置和一些值NLog.config).
我已经按照这里的步骤进行操作,它非常适合更改Web.Config中的设置(例如,Web.PublishProfile1.Config的转换得到尊重).
这是我的 NLog.PublishProfile1.Config转换文件:
<nlog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform" xmlns="http://www.nlog-project.org/schemas/NLog.xsd">
<nlog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets >
<target xsi:type="File"
name="tracelog"
fileName="NEW_VALUE_HERE" layout="${longdate} [${threadname}::${threadid}] ${pad:padding=5:inner=${level:uppercase=true}} ${logger} - ${message}"
xdt:Transform="Replace" xdt:Locator="Match(name)" />
</targets>
</nlog>
</nlog>
Run Code Online (Sandbox Code Playgroud)
问题是我在NLog.PublishProfile1.config中有相同的转换,但是在部署之后也不会应用这些转换.
有没有人知道为什么这个转换对NLog.config不起作用但对发布配置文件中的Web.config有效?
有没有办法将NLog.config信息放在我的app.config文件中?这样我可以有一个配置文件而不是两个.它可能看起来像这样:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="nlog" type="..." />
</configSections>
<nlog>
<targets>...</targets>
<rules>...</rules>
</nlog>
</configuration>
Run Code Online (Sandbox Code Playgroud)
如果这是重复,请告诉我.
我正在使用NLog来记录我的asp.net mvc(C#)应用程序中的异常.
NLog无法在发布模式下工作.在调试模式下运行时也一样.
可能是什么问题?有没有解决这个问题?
我有一个基于Tekpub Starter Site的MVC2应用程序,所以它使用Ninject进行依赖注入,NLog用于日志记录,以及各种各样的其他库.据我所知,正是这些导致了我的问题.
使用ASP.NET开发服务器(Cassini)在我的PC上工作得非常好但是当我部署到服务器(这是一个廉价的共享主机交易)时,我得到一个NullReferenceException似乎与Ninject实例化记录器有关.
这是我的Global.asax.cs的相关位
protected override void OnApplicationStarted() {
Logger.Info("App is starting"); // <-- I think this is what's causing the problem
RegisterRoutes(RouteTable.Routes);
//MvcContrib.Routing.RouteDebugger.RewriteRoutesForTesting(RouteTable.Routes);
RegisterAllControllersIn(Assembly.GetExecutingAssembly());
SetEngines();
}
protected override IKernel CreateKernel() {
return Container;
}
internal class SiteModule : NinjectModule {
public override void Load() {
Bind<ILogger>().To<NLogLogger>();
// and a couple of others...
}
}
protected void Application_End() {
Logger.Info("App is shutting down");
}
protected void Application_Error() {
Exception lastException = Server.GetLastError();
Logger.Fatal(lastException);
}
public ILogger Logger …Run Code Online (Sandbox Code Playgroud) dependency-injection shared-hosting ninject nlog asp.net-mvc-2
我正在使用NLog进行日志记录.目前我的Layout-String是:
"${date:format=dd.MM.yyyy HH\\:mm\\:ss,fff} | ${level:uppercase=true} | ${message}"
Run Code Online (Sandbox Code Playgroud)
这会产生以下日志:
18.12.2013 11:23:14,834 | INFO | this is an info
18.12.2013 11:23:14,835 | TRACE | this is a trace
Run Code Online (Sandbox Code Playgroud)
我现在想要的是格式化"$ level"以填充Whitespaces,使其看起来像一个包含5个字符的表.
我想拥有:
18.12.2013 11:23:14,834 | INFO | this is an info
18.12.2013 11:23:14,835 | TRACE | this is a trace
Run Code Online (Sandbox Code Playgroud)
我没有发现任何遗憾......任何人都可以帮忙吗?
nlog ×10
.net ×2
asp.net-mvc ×2
c# ×2
app-config ×1
asp.net ×1
deployment ×1
format ×1
log4net ×1
logging ×1
maui ×1
ninject ×1
web-config ×1
whitespace ×1
xslt ×1