- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我已经阅读了一堆主题相似的 SO 帖子,似乎没有一个能解决我的问题。
我的 nlog.config
类似于:
<?xml version="1.0" encoding="utf-8"?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xsi:schemaLocation="NLog NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true"
throwExceptions="true"
internalLogIncludeTimestamp="true"
internalLogFile="nlog-internal.log"
internalLogLevel="Error">
<extensions>
<add assembly="NLog.Web.AspNetCore"/>
</extensions>
<targets>
<target xsi:type="Database"
name="database"
commandType="Text"
dbProvider="Npgsql.NpgsqlConnection, Npgsql"
connectionString="${var:appDbConnectionString}"
commandText="Layout">
<commandText>
insert into "logs" ("application", "user", "level", "message", "exception", "logger")
values (@application, @user, @level, @message, @exception, @logger);
</commandText>
<parameter name="@application" layout="My App" />
<parameter name="@user" layout="${aspnet-user-identity}" />
<parameter name="@level" layout="${level}" />
<parameter name="@message" layout="${message}" />
<parameter name="@exception" layout="${exception:format=tostring}" />
<parameter name="@logger" layout="${logger}" />
</target>
</targets>
<rules>
<logger name="MyApp.*" minlevel="Info" writeTo="database" final="true" />
<logger name="*" minlevel="Error" writeTo="database" final="true"/>
<logger name="*" minlevel="Warn" writeTo="database" final="true"/>
</rules>
</nlog>
...我的 Startup.cs
在 ConfigureServices()
方法中调用它:
services.AddLogging();
...我的 Startup.cs
在 Configure()
方法中调用它:
var loggerFactory = app.ApplicationServices.GetService<ILoggerFactory>();
LogManager.LoadConfiguration("nlog.config");
LogManager.Configuration.Variables["appDbConnectionString"] =
config["ConnectionStrings:ApplicationContext"];
loggerFactory.AddNLog();
...我的 Program.cs
中的 BuildWebHost(string[] args)
有:
public static IWebHost BuildWebHost(string[] args)
{
return WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseNLog()
.Build();
}
我的 ClaimsPrincipal 已正确填写并配置了经过身份验证的用户,但我无法将 {aspnet-user-identity}
设为空白以外的任何内容。 p>
我做错了什么?
我正在使用 NLog 4.5.10、NLog.Extensions.Logging 1.3.0 和 NLog.Web.AspNetCore 4.7.0;这些似乎是最新的库。
最佳答案
事实证明,当 NLog 与 IoC 容器一起使用时,它实现了自己的服务定位器。我需要像这样添加一行:
app.ApplicationServices.SetupNLogServiceLocator();
...奇迹发生了。我不得不写一个 issue in GitHub为此,他们几乎立即做出了回应
关于c# - NLog .NET Core aspnet-user-identity 始终为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52884266/
我想更改 nlog 布局,以便显示两个条目之间的时间。这样的布局可能吗? 这是我现在的输出,如果在时间旁边有自之前进入以来经过的秒数,那就太好了。 2012-05-20 19:18:41.09
使用 NLog v4.4.12,我的 App.config 中有这个 这是我的 Variables.xml 文件内容 但是我在启动我的应
我有一个名为 的自定义布局渲染器工作 .它提供了几个项目,它们在我们的 app.config 中是这样使用的: 当
NLog 是否可以发出多行消息,以便每行都根据当前布局进行格式化?例如。 2015-12-17 11:37:38.0845 | 64 | INFO | ------------------------
我刚开始玩 nlog,注意到 nlog.xml 文件与 nlog.dll 一起被带到了应用程序的输出文件夹中。我不太清楚该文件的用途以及我是否应该将它作为我的应用程序安装的一部分或可以安全地删除它。有
是否可以/容易使用 Rhino Mocks 或类似方法模拟 NLog 日志方法? 最佳答案 使用 Nuget:install-package NLog.Interface 然后:ILogger log
目标: 当我打电话时Logger.Error("some message", e) ,其中 e是一些异常对象,它只记录消息,不记录异常信息。我需要它来输出异常消息和堆栈跟踪。任何想法我做
在生产环境中更改 nLog 日志记录级别的最佳做法是什么。我可以更改它的唯一方法是修改 NLog.config 文件,然后回收应用程序池。应该这样吗? 谢谢, 克里斯 最佳答案 如果你想改变日志配置而
我已经创建了一个通用实现 ILogger 并在这个包装器中实现了 NLog 实现方法。我的问题是我在我的解决方案中为整个 namspace 启用了错误严重性,但我还希望对“Employee”命名空间下
我在 NLog.config 中配置了两条规则: 我正在尝试使用以下代码写入第一个: LogEventInfo eventInfo = new LogEventInfo(); eventInfo.
我正在尝试将一堆应用程序使用的现有日志记录库转换为使用 NLog。现有的日志记录代码没有间接性,日志记录调用直接从调用者到 Web 服务调用。现有的日志记录代码是作为静态单例实现的。我需要以这样一种方
我有一个泛型类: public class GenericClass { private static readonly Logger Logger = LogManager.GetCurre
在我看来,NLog 中的内置日期格式没有正确包含时区。我们需要用尾随 Z 记录 UTC 时间,以便 Splunk 知道本地时间是什么,例如: {日期:universalTime=true:format
我们提供了一个用于日志记录的框架程序集,它在内部使用 nlog。我们还提供了一个嵌入式 nlog 配置作为我们程序集中的资源,并在启动时读取它(包装器中的静态构造函数,它使用 XmlLoggingCo
我这样编码: private static readonly ILogger Logger = LogManager.GetCurrentClassLogger(); public MyClass()
现在我这样做 LogManager.DisableLogging(); 但这需要再次部署我的代码,如何从 nlog 配置文件中禁用登录。 最佳答案 关于nlog - 从 Nlog.config 发
我想弄清楚如何阻止 NLog 替换我正在记录的字符串中的换行符。我希望输出包含所有换行符,而不是将整个输出放在一行中。 有人可以帮忙吗? 配置: 代码
作为从 NLog 切换到 Serilog 的一个步骤,我想重定向 NLog 的 LogManager.GetLogger(name) 的标准调用的标准接线,以桥接任何记录到 NLog 的代码,以便立即
为此,我需要一份详细/分步指南。我已经阅读了简要指南 ( example here ) 并下载了示例代码,但我仍然无法弄清楚如何使用 Nlog 登录到 CloudWatch。 当我在 NLog.con
我将 NLog 错误电子邮件文本的内容放入一个文件中,并使用 FileContents 渲染器进行渲染。如果布局渲染器产生空字符串,我想做的是隐藏 html 输出的某些部分 Request ticke
我是一名优秀的程序员,十分优秀!