-
Notifications
You must be signed in to change notification settings - Fork 165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Getting-started-with-ASP.NET-Core vs2017 #157
Comments
i moved the |
Is this on ASP.NET Core 2? |
I'm using asp.Net core 1.2.
But this message is actually wrong. if i log inside a class that doesn't
have action and controller, then this message will appear.
…On Jun 26, 2017 17:48, "Julian Verdurmen" ***@***.***> wrote:
Is this on ASP.NET Core 2?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#157 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AIk0J3TonAQ2F58NVmi5cwn7ytBL-lwRks5sH35ZgaJpZM4OAXnd>
.
|
could you please give an example? I'm not fully get it, thanks! |
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, ApplicationDbContext context, IServiceProvider services, Paths pathHelper)
{
ILogger<Startup> logger = null;
if (loggerFactory != null)
{
//loggerFactory.AddConsole(Configuration.GetSection("Logging"));
//loggerFactory.AddDebug();
loggerFactory.AddNLog();
app.AddNLogWeb();
env.ConfigureNLog("nlog.config").Reload();
/*
i also have env.ConfigureNLog("nlog.config") at the startup constructor,
but still after `addNlogWeb` i'm trying to configure nlog and reload it,
still getting the message to load IHttpContext first
*/
// here i'm loading the service manually
logger = services.GetService<ILogger<Startup>>();
logger.LogInformation($"logger started, env is {env.EnvironmentName}");
}
if (env.IsDevelopment() || env.IsStaging())
{
logger?.LogInformation("entred the development mode");
app.UseStatusCodePages();
app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();
app.UseBrowserLink();
}
....
} the log look like this :
but if i call logger in normal way that suggested by asp.net in a controller i will get log like bellow:
which is right. so i am thinking the error is caused by empty <target xsi:type="File" name="ownFile-web" fileName=".\logs\nlog-own-${shortdate}.log"
layout="${longdate}|${event-properties:item=EventId.Id}|${logger}|${uppercase:${level}}| ${message} ${exception} ${when:when=length('${aspnet-request-url}')>0:Inner=|url${literal:text=\:} ${aspnet-request-url}} ${when:when=length('${aspnet-mvc-action}')>0:Inner=|action${literal:text=\:} ${aspnet-mvc-action}} " /> |
This is correct? There isn't a url and page when you're in |
@304NotModified I have exactly the same problem. |
@304NotModified at that time the IHttpContext didn't build yet, plus it is part of the application start. |
@KolyaNET you can't do that on startup, if you want to capture all the URL, then you need to create a middlewear |
I'm a bit confused. Is there something we (NLog) could do or is this resolved? |
I resolved mine with the change on the first post but just wanted confirmation if that was intended use. I'm not sure about the others. |
ConfigureNLog() needs to go after AddNLogWeb() to avoid the warning (but this seems odd...) public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddNLog();
app.AddNLogWeb();
env.ConfigureNLog("nlog.config");
} |
Got the same warnning.
|
I get the same warning. My Startup.cs looks just like the Getting Started Guide. On asp.net core 1.1.2. I tried moving |
Getting the same issue, tried moving it and still getting the warning. |
But does it work? |
Have the same issue. Is there a solution? I have the following code and and still have the warning
|
I'm not sure if it helps with the problems mentioned here, but in my case, the trick was to have |
warning exists with core 2.0, cannot seem to get rid of it |
Same issue with Core 2.0 this is my first time using it and I want to log to SQL but this first attempt using the WIKI example is not giving me high hopes. |
I have same warning with .net core 2.0. All logging fields like aspnet-* are not included in logs. |
I think that's another issue. It will be hard to fix this issue if we getting off topic. AFAIK its only a warning and everything works. We will fix the warning but isn't critical. Don't get me wrong. Good docs are important but currently I have to invest some time before I could update the docs. If someone has a working fix, please let me know. |
I will try to fix this, this weekend. I think we have to move all config to the |
@304NotModified Yes logging config should be done in the app's |
Hi 304NotModified: Thanks for the great work! |
Was this fix ever released? |
I followed https://github.com/NLog/NLog.Web/wiki/Getting-started-with-ASP.NET-Core-(csproj---vs2017) for my VS2017 .NET Core project. Step 4 shows the following:
That doesn't work for me since
Startup
runs beforeConfigureServices
. WhenConfigureNLog
runs I get the following error:2017-06-20 21:39:37.7335 Warn Missing IHttpContextAccessor. Has it been registered before loading NLog Configuration? Consider reloading NLog Configuration after having registered the IHttpContextAccessor.
I fixed it by moving
ConfigureNLog
inside of theConfigure
method and taking aIHostingEnvironment
parameter, but was wondering if the documentation was incorrect or if the code was intended to be used that way somehow.The text was updated successfully, but these errors were encountered: