Skip to content
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

.NET Core 2.0: Not getting all my log messages #175

Closed
sarchibald-mdsol opened this issue Sep 26, 2017 · 9 comments
Closed

.NET Core 2.0: Not getting all my log messages #175

sarchibald-mdsol opened this issue Sep 26, 2017 · 9 comments
Labels
ASP.NET Core ASP.NET Core - all versions duplicate question

Comments

@sarchibald-mdsol
Copy link

sarchibald-mdsol commented Sep 26, 2017

I'm using .net core 2.0 and Visual Studio 2017. I've installed the latest version of NLog.Web.AspNetCore(4.4.1).

My nlog.config is:

<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
	  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	  autoReload="true"
	  internalLogLevel="Info"
	  internalLogFile="c:\logs\internal-nlog.log">
	<!-- Load the ASP.NET Core plugin -->
	<extensions>
		<add assembly="NLog.Web.AspNetCore"/>
	</extensions>
	<!-- the targets to write to -->
	<targets>
		<!-- write logs to file -->
		<target xsi:type="File" name="allfile" fileName="c:\logs\cdcdashboard.${shortdate}.log"
					layout="${longdate}|${event-properties:item=EventId.Id}|${uppercase:${level}}|${message} ${exception}" />
		<!-- write to the void aka just remove -->
		<target xsi:type="Null" name="blackhole" />
	</targets>
	<!-- rules to map from logger name to target -->
	<rules>
		<!--All logs, including from Microsoft-->
		<logger name="*" minlevel="Trace" writeTo="allfile" />
		<!--Skip Microsoft logs and so log only own logs-->
		<logger name="Microsoft.*" minlevel="Trace" writeTo="blackhole" final="true" />
	</rules>
</nlog>

I'm getting all the Microsoft log entries as expected, but none of my custom log items.
Here's the relevant code:

using System.Web;
using CDCDashboard.Domain.Models;
using CDCDashboard.Mappers;
using CDCDashboard.Service;
using CDCDashboard.ViewModel;
using Microsoft.Extensions.Logging;

namespace CDCDashboardWeb.Controllers
{
	public class RaveCDCEstimationsController : BaseController<RaveCdcEstimations>
	{
		RaveCDCEstimationsService service;
		public RaveCDCEstimationsController(NeoHelperContext dbContext, ILogger<RaveCdcEstimations> logger) : base(dbContext){
			service = new RaveCDCEstimationsService(dbContext);
			this.logger = logger;
		}

		[Microsoft.AspNetCore.Mvc.Route("api/GetDatabaseGB")]
		public BaseValueStatCollectionViewModel GetDatabaseGB(string xAxisLabel, string yAxisLabel)
		{
			var result = new BaseValueStatCollectionViewModel();
			var rawQryString = this.Request.QueryString.Value;
			var qryCollection = HttpUtility.ParseQueryString(rawQryString);
			var nodes = service.Get(qryCollection);
			result = MapRaveCdcEstimations.MapToBaseValueStatCollectionVM(nodes, xAxisLabel, yAxisLabel);
			logger.LogDebug($"Exiting:: returning {result.NodeStats.Count.ToString()} nodes");
			return result;
		}
	}
}

I'm not seeing anything from logger.LogDebug("Entering", null); even though I can step through that line successfully in debug.
Here's what does show up in my log file:

2017-09-26 12:48:26.4453|11|FATAL|Hosting startup assembly exception Startup assembly Microsoft.AspNetCore.ApplicationInsights.HostingStartup failed to execute. See the inner exception for more details.
2017-09-26 12:48:26.6492|1|INFO|Request starting HTTP/1.1 GET http://localhost:4303/api/GetDatabaseGB?$top=150&$orderby=DatabaseSizeGB%20desc   
2017-09-26 12:48:26.9730|1|INFO|Executing action method CDCDashboardWeb.Controllers.RaveCDCEstimationsController.GetDatabaseGB (CDCDashboardWeb) with arguments (, ) - ModelState is Valid 
2017-09-26 12:48:27.5292|1|INFO|Executing ObjectResult, writing value Microsoft.AspNetCore.Mvc.ControllerContext. 
2017-09-26 12:48:27.5876|2|INFO|Executed action CDCDashboardWeb.Controllers.RaveCDCEstimationsController.GetDatabaseGB (CDCDashboardWeb) in 737.1523ms 
2017-09-26 12:48:27.5876|2|INFO|Request finished in 945.4005ms 200 application/json; charset=utf-8 
@304NotModified
Copy link
Member

304NotModified commented Sep 26, 2017

ILoggingBuilder.SetMinimumLevel()

see #167 and NLog/NLog.Extensions.Logging#128

@304NotModified
Copy link
Member

304NotModified commented Sep 26, 2017

I've added some notes to the readmes!

closing as duplicate of #167 and NLog/NLog.Extensions.Logging#128

@sarchibald-mdsol
Copy link
Author

Thanks! That solved my problem. Now I'm getting too much from ASP.NET, but I'll figure out how to turn that off...

@304NotModified
Copy link
Member

with the blackhole construction in NLog's config

@304NotModified
Copy link
Member

but there is probably also another API option (the filters from MS)

@304NotModified
Copy link
Member

304NotModified commented Dec 6, 2017

@sarchibald-mdsol could you share your NLog set-up ('main' or startup)? Suddenly if has also this problem in my example. Thanks!

@304NotModified
Copy link
Member

304NotModified commented Dec 6, 2017

@sarchibald-mdsol

you have responded on sep 27 in this thread.

and im curious if you could elaborate on your solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ASP.NET Core ASP.NET Core - all versions duplicate question
Projects
None yet
Development

No branches or pull requests

3 participants