[英]NLog File is not Generated in ASP.Net Core Web MVC
I'm new developer trying to create a solution that has several projects in Visual Studio 2019 with C# language.我是新开发人员,试图创建一个解决方案,该解决方案在 Visual Studio 2019 中使用 C# 语言拥有多个项目。 I need to create one NLog.config file and used by all the other projects.我需要创建一个 NLog.config 文件并供所有其他项目使用。 So I create an Infrastructure Layer Project that has Nlog.Config file and I do all the configuration, within the Infrastructure Layer Project所以我创建一个基础设施层项目有Nlog.Config文件,我做的所有配置,基础设施层项目中
In Nlog.Config file I wrote在我写的Nlog.Config 文件中
<targets>
<target xsi:type="File" name="LogFile" fileName="${basedir}/logs/${shortdate}.log"
layout="${longdate} ${uppercase:${level}} ${message}" />
</targets>
<rules>
<logger name="LogRules" minlevel="Debug" writeTo="LogFile" />
</rules>
I create a class named ApplicationBase with code我用代码创建了一个名为ApplicationBase的类
public class ApplicationBase
{
protected Logger Log { get; private set; }
protected ApplicationBase(Type declaringType)
{
Log = LogManager.GetLogger(declaringType.FullName);
}
}
I create another class named EmpVO with a code我用代码创建了另一个名为EmpVO 的类
public class EmpVO : ApplicationBase
{
public EmpVO() : base(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)
{
Log.Info("Instance created");
}
}
I create another project named presentation layer , that is an Empty web ASP.net Core 3.0, with start.cs file我创建了另一个名为presentation layer 的项目,它是一个空的web ASP.net Core 3.0,带有start.cs 文件
I wrote我写
public void ConfigureServices(IServiceCollection services)
{
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
EmpVO emp = new EmpVO();
}
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapGet("/", async context =>
{
await context.Response.WriteAsync("Hello World!");
});
});
}
The solution working fine with no errors and built it with no errors.该解决方案工作正常,没有错误,并且没有错误地构建它。 But cannot generate an initial NLog file.但无法生成初始 NLog 文件。
So what should I do to make it generate the NLog and to have one single NLog file to be used by all other projects.那么我应该怎么做才能使它生成 NLog 并让所有其他项目使用一个 NLog 文件。
The name
attribute in the <logger>
is a name filter. <logger>
的name
属性是一个名称过滤器。 So currently you only route logs from the LogRules logger to you target.因此,目前您只能将日志从 LogRules 记录器路由到您的目标。
Start otherwise with name="*"
:否则以name="*"
开头:
<logger name="*" minlevel="Debug" writeTo="LogFile" />
And if it's unclear what your logger name is, you could also log that with ${logger}
如果不清楚您的记录器名称是什么,您也可以使用${logger}
See also the docs for logger rules另请参阅记录器规则的文档
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.