ASPNET Core 2.0 with latest Nlog.
All config files load correctly.
My config file is simple, I just want it to log every thing.
<?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="Warn"
internalLogFile="C:\wwwLogs\nlog.log">
<extensions>
<add assembly="NLog.Web.AspNetCore"/>
</extensions>
<targets>
<target xsi:type="File" name="allfile" fileName="C:\wwwLogs\${shortdate}.log"
maxArchiveFiles="90"
archiveNumbering="DateAndSequence"
archiveAboveSize="250000"
archiveFileName="archive/log.{#######}.log"
archiveEvery="Day"
concurrentWrites="true"
layout="${longdate}|${logger}|${uppercase:${level}}|${message} ${exception}" />
</targets>
<rules>
<!--All logs, including from Microsoft-->
<logger name="*" minlevel="Trace" writeTo="allfile" />
</rules>
</nlog>
I can see it in the trace log for nlog it is setting all levels to the correct output.
2017-11-01 14:21:26.3017 Trace Opening C:\wwwLogs\2017-11-01.log with allowFileSharedWriting=False
2017-11-01 14:21:28.5859 Debug Targets for TimeSlotApprovalService by level:
2017-11-01 14:21:28.5859 Debug Trace => allfile
2017-11-01 14:21:28.5859 Debug Debug => allfile
2017-11-01 14:21:28.5859 Debug Info => allfile
2017-11-01 14:21:28.5859 Debug Warn => allfile
2017-11-01 14:21:28.5859 Debug Error => allfile
2017-11-01 14:21:28.5859 Debug Fatal => allfile
In my application when I call this
_logger.LogDebug(JsonConvert.SerializeObject(resultList, Formatting.Indented));
_logger.LogError(JsonConvert.SerializeObject(resultList, Formatting.Indented));
_logger.LogCritical(JsonConvert.SerializeObject(resultList, Formatting.Indented));
_logger.LogWarning(JsonConvert.SerializeObject(resultList, Formatting.Indented));
_logger.LogTrace(JsonConvert.SerializeObject(rankedTimeSlots, Formatting.Indented));
Then the log file only logs these
2017-11-01 14:44:48.2570|TimeSlotApprovalService|**ERROR**|[json...
2017-11-01 14:44:48.2570|TimeSlotApprovalService|**FATAL**|[json...
2017-11-01 14:44:48.2570|TimeSlotApprovalService|**WARN**|[json...
Where are the rest?? Trace and Debug?? Info?
ASP.NET Core and its logging system Microsoft.Extensions.Logging use a central configuration. This configuration applies regardless of the attached logging providers. So if you use NLog as a logging provider, you will still have to configure the logging infrastructure.
By default, the web host builder will automatically use the configuration within the appsettings.json to configure the logging verbosity. And in the default template, this is what the configuration looks like:
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Warning"
}
}
}
So the default minimum log level to log is Warning. So even if you configure your NLog provider to log at any logging level, it won’t actually receive logging instructions lower than Warning from the logging system.
So you will have to adjust the configuration there to change it. Set it to Trace and it should log everything.
Note that you should still consider using the configuration there as the source of truth on what log levels should be logged. So just keep your NLog configuration to log whatever it gets, and then adjust your appsettings.json to match whatever you want to actually log, depending on the current enviroment (you can create files like appsettings.Development.json and appsettings.Production.json to create environment-specific configurations).
If you want to do it by code:
var services = new ServiceCollection();
services.AddLogging((builder) => builder.SetMinimumLevel(LogLevel.Trace));
Related
My package is installed in sideloaded way and keeps encountering the app-specific permission error.
Yes many suggest to alter permissions and owners manully in regedit and Component Services.
My app is actually missing in the DCOM Config under the Component Services (DCOMCNFG, DCOMCNFG -32).
I see neither errors in the proc monitor nor warnings. How can I grant permissions in this case and why isn't this specific task accomplished by the MSIX installer ?
The application-specific permission settings do not grant Local Activation permission for the COM Server application with CLSID
{2593F8B9-4EAF-457C-B68A-50F6B8EA6B54}
and APPID
{15C20B67-12E7-4BB6-92BB-7AFF07997402}
to the user PRECISION\Tommy SID (S-1-5-21-3771326467-2290839719-591499861-1001) from address LocalHost (Using LRPC) running in the application container Unavailable SID (Unavailable). This security permission can be modified using the Component Services administrative tool.
I attmepted to grant DCOM permission by using this PS modul but to no avail:
Grant, Revoke, Get DCOM permissions using PowerShell
Import-Module .\DCOMPermissions
Grant-DCOMPermission -ApplicationID "{9CA88EE3-ACB7-47C8-AFC4-AB702511C276}" -Account "SYSTEM" -Type Launch -Permissions LocalLaunch,LocalActivation -OverrideConfigurationPermissions
Keep witnessing the error in the Event Viewer and this prohibits my app to start up:
Event Viewer exhibiting the error ID 10010
I build the MSIX package with the help of this AppxManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<Package xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10">
<Identity Name="WeatherHistory" Version="0.7.0.2" Publisher="CN=Contoso Software, O=Contoso Corporation, C=US" />
<Properties>
<DisplayName>Weather History</DisplayName>
<PublisherDisplayName>Cosmic ray</PublisherDisplayName>
<Logo>Images/satelite.png</Logo>
</Properties>
<Dependencies>
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.17763.0" MaxVersionTested="10.0.18363.0" />
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.17763.0" MaxVersionTested="10.0.18363.0" />
</Dependencies>
<Resources>
<Resource Language="en-us" />
</Resources>
<Applications>
<Application Id="Weather.History" Executable="Weather.History.Splash.exe" EntryPoint="Weather.History.Splash">
<VisualElements DisplayName="Weather History" Description="Frontend" Square150x150Logo="Images/satelite.png" Square44x44Logo="Images/satelite.png" BackgroundColor="yellow" xmlns="http://schemas.microsoft.com/appx/manifest/uap/windows10" />
<Extensions>
<Extension Category="windows.fullTrustProcess" Executable="Weather.History.Stylet.exe" xmlns="http://schemas.microsoft.com/appx/manifest/desktop/windows10" />
</Extensions>
</Application>
</Applications>
<Capabilities>
<Capability Name="runFullTrust" xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" />
<Capability Name="internetClient" />
</Capabilities>
</Package>
... and addded code to my package entry point exe as
private async void LaunchProduct()
{
try
{
if (ApiInformation.IsApiContractPresent("Windows.ApplicationModel.FullTrustAppContract", 1, 0))
{
await FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync();
}
else
{
Exit($"Your Windows version is not supported.");
}
}
catch (Exception e)
{
Exit("Failed to launch Weather History", e);
}
}
There is a WPF splash attempts to launch another WPF both are based on the common TFM .NET 4.7. The first WPF ought to launch the second as a trusted process harnessing this MSIX package extension infrastructure. Pro boostrapper mechanism. If my take on is right.
This ain't a pacage bundle, so what architecture is my package actually targeting ? I always compile Any CPU.
I finally build the package by invoking the respective tool as :
makeappx.exe pack /v /o /f mapping.map /m Appxmanifest.xml /p ./Weather.History.msix
The EntryPoint indeed must be designated as trusted.
EntryPoint="Windows.FullTrustApplication"
I'm trying to set up logging for my application using NLog. The app is running in a docker service along with other services such as a database. I'm not sure if that creates any issues, but I doubt it as I set up internal logging and that works fine. I set up NLog to have two targets: a console target and a file target. The internal log tells me it loaded those two targets from my config I specified. Now, the weird thing is, I get console output, but no file gets created.
nlog.config
<?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="logs/internal-nlog.txt">
<!-- enable asp.net core layout renderers -->
<extensions>
<add assembly="NLog.Web.AspNetCore"></add>
</extensions>
<!-- the targets to write to -->
<targets>
<!-- console log -->
<target name="consolelog" xsi:type="Console"></target>
<target name="logfile" xsi:type="File" fileName="logs/${shortdate}-n.txt" Layout="${longdate}|${level:uppercase=true}|${logger}|${message}"></target>
</targets>
<!-- rules to map from logger name to target -->
<rules>
<!-- log everything from application namespace to console -->
<logger name="vote_server.*" minlevel="Trace" writeTo="consolelog"></logger>
<!-- log everything from application namespace to file -->
<logger name="vote_server.*" minlevel="Trace" writeTo="logfile"></logger>
</rules>
</nlog>
I have a bit of a conundrum here. For some reason my Nlog implementation will no longer work from an installed executable, works perfectly well from the VS2013 development environment, but nada from the installed executable.
DevEnv is VB.NET.
My first port of call in terms of diagnostics was to add:
internalLogFile="c:\log.txt" internalLogLevel="Trace"
to the nlog.config file, but this suffers from the same problem, (works in devenv but not from executable). My log files get written to a folder structure in the CommomApplicationData folder,
d:\programdata\CompanyName\AppName\Logs
nlog.config is installed in and read from:
d:\programdata\CompanyName\AppName\QueryConfig
the reason for this is that our corporate IT security prohibits writes to the C: drive (other than via authorised installs), and I have a variable in the nlog.config file 'LogId', that needs to be updated from the app. Here is my nlog.config file:
<?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"
internalLogFile="c:\log.txt" internalLogLevel="Trace">
<variable name="companyName" value="Company Name"/>
<variable name="logFolder" value="${specialfolder:folder=CommonApplicationData}/${companyName}/AppName/Logs/"/>
<variable name="startDelim" value="["/>
<variable name="endDelim" value="]"/>
<variable name="filename" value="${date:format=yyyy-MM-dd}_${gdc:item=appName}.log"/>
<variable name="fieldDelim" value="|"/>
<variable name="logId" value="1"/>
<variable name="headerLayout" value="Application Name: ${processname} File Version: ${gdc:item=fileVersion} Released: ${gdc:item=releaseDate} User: ${windows-identity}" />
<variable name="normalLayout" value="${gdc:item=logId}${fieldDelim}${date:format=HH\:mm\:ss}${fieldDelim}${windows-identity}${fieldDelim}${level}${fieldDelim}${message}${exception:format=tostring}" />
<variable name="traceLayout" value="${gdc:item=logId}${fieldDelim}${date:format=HH\:mm\:ss}${fieldDelim}${windows-identity}${fieldDelim}${level}${fieldDelim}${message}${exception:format=tostring}"/>
<targets async="true">
<target name="fileHeader"
xsi:type="File"
fileName="${logFolder}${filename}"
layout="${headerLayout}"/>
<target name="normal"
xsi:type="File"
fileName="${logFolder}${filename}"
layout="${normalLayout}"/>
</targets>
<rules>
<logger name="HeaderLogger" minlevel="Info" writeTo="fileHeader" final="true"/>
<logger name="*" minlevel="Trace" writeTo="normal" />
</rules>
</nlog>
This Nlog implementation has worked fine for the last 5 years the only difference is the diversion of the nlog.config and log file destination to the CommonApplicationData folder. Testing of a windows service app that uses the same logging implementation works fine from the same machine, the only differences are that it runs as a service under the system account and does not require write access to the Nlog.config file, as a consequence of which nlog.config resides in the application folder on the C: drive. Hope somebody has some input into this because its driving me crazy...!
Edit: I should add, that I have full Admin rights on this machine under my corporate user ID, however normal users won't.
Kind Regards
Paul J.
EDITED 2018-08-14
OK, so... as suggested have altered the relevant code to launch internal logging programmatically to write to log.txt in c:\temp. Curiously, this appears to work to an extent. However content of the output is rather sparse when compared to internal log output when launched via the config file. As expected, the actual application logging remains inactive.
Sample log from log.txt when internal logging implemented programmatically:
2018-08-13 15:21:34.9302 Debug Targets for HeaderLogger by level:
2018-08-13 15:21:34.9302 Debug Trace =>
2018-08-13 15:21:34.9302 Debug Debug =>
2018-08-13 15:21:34.9302 Debug Info =>
2018-08-13 15:21:34.9412 Debug Warn =>
2018-08-13 15:21:34.9412 Debug Error =>
2018-08-13 15:21:34.9412 Debug Fatal =>
2018-08-13 15:21:37.0902 Debug Targets for HeaderLogger by level:
2018-08-13 15:21:37.0902 Debug Trace =>
2018-08-13 15:21:37.0902 Debug Debug =>
2018-08-13 15:21:37.0932 Debug Info =>
2018-08-13 15:21:37.0932 Debug Warn =>
2018-08-13 15:21:37.0932 Debug Error =>
2018-08-13 15:21:37.0932 Debug Fatal =>
2018-08-13 15:21:39.1012 Trace LogFactory.Flush(00:00:15)
...
finally when the app is closed down the log finishes with:
2018-08-13 15:35:56.9262 Info Shutting down logging...
2018-08-13 15:35:56.9262 Info Logger has been shut down.
Kind Regards
Paul.
I have mule flow, trying to deploy it, it says that "Config for app not found"
I have created a dummy mule-config.xml under src/main/app, given below. My flow is:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:jersey="http://www.mulesoft.org/schema/mule/jersey" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:core="http://www.mulesoft.org/schema/mule/core" version="EE-3.4.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/jersey http://www.mulesoft.org/schema/mule/jersey/current/mule-jersey.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd">
<flow name="webservicesFlow1" doc:name="webservicesFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="slmule2.corp.local" port="8088" path="rest" doc:name="HTTP"/>
<jersey:resources doc:name="REST">
<component class="com.rest.sample.RestComponent"/>
</jersey:resources>
</flow>
</mule>
mule-deploy.properties
redeployment.enabled=true
encoding=UTF-8
domain=default
config.resources=webservices.xml
mule-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.0/mule.xsd">
<!-- empty config to avoid the hot deployment classloader choking on a missing config file -->
</mule>
Error message:
ERROR 2014-06-12 12:58:06,575 [Mule.app.deployer.monitor.1.thread.1] org.mule.module.launcher.MuleDeploymentService:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + Failed to deploy app + +
'webservices-1.0.0-SNAPSHOT-v20140612-12+57', + + see below +
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
org.mule.module.launcher.InstallException: Config for app 'historydata-1.0.0-SNAPSHOT-
v20140612-12+57' not found: /apps/mulesoft/mule-enterprise-standalone-3.4.2/apps
/webservices-1.0.0-SNAPSHOT-v20140612-12+57/webservices.xml at
org.mule.module.launcher.application.DefaultMuleApplication.install(DefaultMuleApplication.j
ava:107) at
org.mule.module.launcher.application.ApplicationWrapper.install(ApplicationWrapper.java:79)
at org.mule.module.launcher.DefaultMuleDeployer.deploy(DefaultMuleDeployer.java:42) at
org.mule.module.launcher.MuleDeploymentService.guardedDeploy(MuleDeploymentService.java:454)
at
org.mule.module.launcher.MuleDeploymentService.deployApplication(MuleDeploymentService.java:
191) at
org.mule.module.launcher.MuleDeploymentService.deployExplodedApp(MuleDeploymentService.java:
708) at
org.mule.module.launcher.MuleDeploymentService.deployExplodedApps(MuleDeploymentService.java
:661) at
org.mule.module.launcher.MuleDeploymentService.access$400(MuleDeploymentService.java:57) at
org.mule.module.launcher.MuleDeploymentService$AppDirWatcher.run(MuleDeploymentService.java:
808) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) at
java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304) at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThr
eadPoolExecutor.java:178) at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPool
Executor.java:293) at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at
java.lang.Thread.run(Thread.java:744) INFO 2014-06-12 12:58:07,859 [2132436410#qtp-
1158879031-6] org.mule.module.launcher.MuleDeploymentService: ================== Request to
Undeploy Application: ambrosehistorydata-1.0.0-SNAPSHOT-v20140612-12+57 INFO 2014-06-12
12:58:07,860 [2132436410#qtp-1158879031-6]
org.mule.module.launcher.application.DefaultMuleApplication: App 'webservices-1.0.0-
SNAPSHOT-v20140612-12+57' never started, nothing to dispose of INFO 2014-0
I am using mule studio 3.5.0 and mule-ee 3.4.
I had the same problem.
when you build your zip, you should zip files, not a directory ...
Dan
Sometimes javaw.exe doesn't seem to let go of a running project and seems to lock access to the config file. Killing javaw.exe and rerunning the project again fixed it.
In your Mule configuration file (src/main/app/app-config-file.xml), you can specify the properties file you want to load.
<context:property-placeholder location="${environment.name}.properties" />
This is the description of the attribute location :
Attribute : location
The location of the properties file to resolve placeholders against,
as a Spring resource location: a URL, a "classpath:" pseudo URL, or
a relative file path. Multiple locations may be specified, separated
by commas. If neither location nor properties-ref is specified,
placeholders will be resolved against system properties.
${environment.name} must be a system environment variable. You need to make sure the system where you are deploying your app contains that variable. I think you can also specify it in the Maven build, if you are using Maven (clean install -Denvironment.name=test). You can try.
To test locally, right click on your project, select run as, select run configurations, click on Environment tab, add your variable "environment.name" and the value "local" (without quotation marks) and make sure your local.properties file exists in a location added to the build path. It can be src/main/app for example or in the resources folder.
I had the same problem too.
My solution, i believe, was simpler.
Instead of exporting the project somehow and then try to deploy it by uploading a zipped file through the browser, I deployed it through Anypoint studio itself.
Right click on the project
Anypoint platform
Deploy to cloud
Sign in with your credentials (if not signed in already)
Choose the proper application and runtime environment then hit deploy.
I have configured Hibernate to use logback logging library. And created an appender that catches logging data from "org.hibernate.SQL" and "org.hibernate.type" loggers. By default, those are set to INFO level.
As the next step I try to change the level of those 2 loggers to DEBUG level using JMX interface of logback. But it does not work and log file contains no data. Only if I set the logging level to DEBUG in the configuration file and then restart the server it works.
Should I do anything additional in order to make Hibernate to start logging?
Here goes the appender/logger configuration:
<configuration debug="false" scan="true" scanPeriod="5 minutes">
<jmxConfigurator />
...
<property name="SQL_LOG_LEVEL" value="DEBUG" />
<appender name="SQL_LOG" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_DIRECTORY}/sql_${weblogic.Name}.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<fileNamePattern>${ROTATION_DIRECTORY}/sql_${weblogic.Name}.%i.log.zip</fileNamePattern>
<minIndex>1</minIndex>
<maxIndex>5</maxIndex>
</rollingPolicy>
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<maxFileSize>50MB</maxFileSize>
</triggeringPolicy>
<encoder>
<pattern>${LOG_PATTERN}</pattern>
</encoder>
</appender>
<logger name="org.hibernate.SQL" level="${SQL_LOG_LEVEL}" additivity="false">
<appender-ref ref="SQL_LOG" />
</logger>
<logger name="org.hibernate.type" level="${SQL_LOG_LEVEL}" additivity="false">
<appender-ref ref="SQL_LOG" />
</logger>
...
</configuration>
EDIT: I have several applications (EAR) files deployed on the same container. All applications are using same logging configuration.
Problem appears to be in fact that I deploy several applications on one sever and, basically, each application's class loader has a copy of logback libraries. That's why several logging context are created, but because they all share the same name ("default"), basically, only one get registered to MBean server.
The solution could be either moving logback libraries higher in class loader hierarchy or use logger context separation as proposed by logback documentation.
I was not able to log any output from org.hibernate.SQL and friends until I set my log level to TRACE instead of DEBUG using logback over slf4j.