NLog environment layout renderer doesn't work when run as a scheduled task - windows

I'm using NLog 4.4.12 with .NET 4.6.2 on Windows Server 2012.
I've configured my app.config with the nlog section as follows:
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<include file="conf/nlog.${environment:MY_ENV}.config"/>
</nlog>
The idea here is that it will bring in an environment specific configuration for setting up NLog.
I setup a System Environment Variable (not user) called MY_ENV, and set its value to production.
If I run the program as the currently logged in user, the proper config file is found, and logs are written as expected.
However, if I setup a scheduled task, through Windows Task Scheduler, to run the program with the same user credentials just used, the Environment Variable seems not to be found?
I have configured the scheduled task to run whether the user is logged on or not, and I have enabled Run with highest privileges.
When I enable the internal diagnostics of NLog, I see the following in the diagnostic log:
2017-10-19 19:27:42.1744 Error Error when including 'conf/nlog..config'. Exception: System.IO.FileNotFoundException: Included file not found: E:\Utilities\MyApp\conf/nlog..config
at NLog.Config.XmlLoggingConfiguration.ParseIncludeElement(NLogXmlElement includeElement, String baseDirectory, Boolean autoReloadDefault)
2017-10-19 19:27:42.1744 Error Parsing configuration from E:\Utilities\MyApp\MyApp.exe.Config failed. Exception: NLog.NLogConfigurationException: Exception when parsing E:\Utilities\MyApp\MyApp.exe.Config. ---> NLog.NLogConfigurationException: Error when including: conf/nlog..config ---> System.IO.FileNotFoundException: Included file not found: E:\Utilities\MyApp\conf/nlog..config
at NLog.Config.XmlLoggingConfiguration.ParseIncludeElement(NLogXmlElement includeElement, String baseDirectory, Boolean autoReloadDefault)
--- End of inner exception stack trace ---
at NLog.Config.XmlLoggingConfiguration.ParseIncludeElement(NLogXmlElement includeElement, String baseDirectory, Boolean autoReloadDefault)
at NLog.Config.XmlLoggingConfiguration.ParseNLogElement(NLogXmlElement nlogElement, String filePath, Boolean autoReloadDefault)
at NLog.Config.XmlLoggingConfiguration.ParseTopLevel(NLogXmlElement content, String filePath, Boolean autoReloadDefault)
at NLog.Config.XmlLoggingConfiguration.Initialize(XmlReader reader, String fileName, Boolean ignoreErrors)
--- End of inner exception stack trace ---
As you can see, it seems to be getting an empty string or null value for the layout rendering of the path for the include file. This results in the file path getting rendered as: conf/nlog..config.
I'm not sure this is a problem with NLog specifically. I looked into the source code for the Environment Layout Renderer, and it eventually calls Environment.GetEnvironmentVariable(string).
I feel like this might have something more to do with the nature of Scheduled Tasks in Windows, but I'm not sure what my options are.
This task needs to run automatically whether the user is logged in or not.
Can someone explain what is going on here? Why is NLog unable to pull in the proper environment variable? What can I do to fix this problem?

I think this is the problem, when changing the environment variable, you need to restart Taskeng.exe.
You should terminate Taskeng.exe and the next time scheduled task is run it will get an updated environment.
https://superuser.com/questions/331077/accessing-environment-variables-in-a-scheduled-task

Related

SonarQube MSBuild End Analysis Failure - Expected X to be a parent of Y

I am encountering the following error on the SonarQube Scanner for MSBuild - End Analysis build task in Visual Studio Team Services.
2017-06-12T14:35:00.1131070Z SonarQube found 7 issues out of which 1 are new
2017-06-12T14:35:00.1131070Z
2017-06-12T14:35:00.1443593Z
2017-06-12T14:35:00.1599853Z ##[error]System.Management.Automation.RuntimeException: Internal Error: expected E:\\CI02\16\s to be a parent of E:\CI02\16\s\path\to\my\file.cs ---> System.Management.Automation.RuntimeException: Internal Error: expected E:\\CI02\16\s to be a parent of E:\CI02\16\s\path\to\my\file.cs
2017-06-12T14:35:00.1599853Z --- End of inner exception stack trace ---
2017-06-12T14:35:00.1599853Z at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)
2017-06-12T14:35:00.1599853Z at System.Management.Automation.PowerShell.Worker.ConstructPipelineAndDoWork(Runspace rs, Boolean performSyncInvoke)
2017-06-12T14:35:00.1599853Z at System.Management.Automation.PowerShell.Worker.CreateRunspaceIfNeededAndDoWork(Runspace rsToUse, Boolean isSync)
2017-06-12T14:35:00.1599853Z at System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
2017-06-12T14:35:00.1599853Z at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
2017-06-12T14:35:00.1599853Z at Microsoft.TeamFoundation.DistributedTask.Handlers.LegacyVSTSPowerShellHost.VSTSPowerShellHost.Main(String[] args)
2017-06-12T14:35:00.1756102Z ##[error]LegacyVSTSPowerShellHost.exe completed with return code: -1.
2017-06-12T14:35:00.1756102Z ##[section]Finishing: Complete the SonarQube analysis
As you can see from the logs it is failing because E:\\CI02\16\s is not a parent of E:\CI02\16\s\path\to\my\file.cs (note the different number of backslashes after E:).
From looking at the build task's source code I can see that it is expecting the the file path to start with the value of the Build.Repository.LocalPath task context variable. I can't see why there is a difference in the number of slashes though.
This only occurrs when the build is triggered from a pull request. If I queue the build manually it succeeds without issue.
I am using version 2.1.2 of SonarQube for Team Services.
Does anyone know a way around this issue or have any suggestions?
The issue resolved itself. I retriggered the build from a pull request the next morning and it succeeded without issue.

SonarQube Install - startsonar.bat fails

SonarQube 6.0 Installation
No plugins currently installed
Presently working through what appears to be connect string problem
In a command prompt, running as Administrator, I enter
StartSonar
This fails with rather cryptic output to the Command Prompt window. The following is what I believe is the relevant excerpt from the sonar.log file:
2016.08.11 12:23:29 INFO web[o.sonar.db.Database] Create JDBC data source for jdbc:sqlserver://localhost/DevOps;databaseName=sonar
2016.08.11 12:23:43 ERROR web[o.a.c.c.C.[.[.[/sonar]] Exception sending context initialized event to listener instance of class org.sonar.server.platform.PlatformServletContextListener
java.lang.IllegalStateException: Can not connect to database. Please check connectivity and settings (see the properties prefixed by 'sonar.jdbc.').
at org.sonar.db.DefaultDatabase.checkConnection(DefaultDatabase.java:104) ~[sonar-db-6.0.jar:na]
at org.sonar.db.DefaultDatabase.start(DefaultDatabase.java:71) ~[sonar-db-6.0.jar:na]
Relevant excerpt from .config file:
sonar.jdbc.url=jdbc:sqlserver://localhost/DevOps:1433;databaseName=sonar
sonar.jdbc.username=SonarQube
sonar.jdbc.password=PassWord1234
Finally, victory is mine! To be fair, I looked at the .config file from TeamCity. Thanks JetBrains!
The correct entries from the .config file (Note backslash / escape characters!):
sonar.jdbc.url=jdbc\:sqlserver\://localhost\\DevOps\:1433;databaseName\=Sonar
sonar.jdbc.username=SonarQube
sonar.jdbc.password=PassWord1234

AdminTask.listTCPEndPoints('abc(abc)') throws exception: ADMF0007E: target object is required

I'm working on deploying application to WebSphere 7 using python script and the script is throwing exception at this line:-
AdminTask.listTCPEndPoints('abc(abc)')
If I run the above command before I run the python script, it works fine. It gives me an error ADMF0003E: Invalid parameter value. But the same command fails in the python script with this error:
wsadmin>AdminTask.listTCPEndPoints('abc(abc)')
WASX7015E: Exception running command: "AdminTask.listTCPEndPoints('abc(abc)')"; exception information: com.ibm.websphere.management.cmdframework.CommandValidationException: ADMF0007E: target object is required.
I can guess that there something in the python script that is causing this issue, but I don't understand why is the AdminTask.listTCPEndPoints command is not able to see the parameter being passed. I'm new to WebSphere, I have only used it in past but never configured it. Any help/insight would be highly appreciated.
Thanks!
Added stack trace of interactive mode option
wsadmin>print AdminTask.listTCPEndPoints('-interactive')
List NamedEndPoints that can be used by a TCPInboundChannel
Lists all NamedEndPoints that can be associated with a TCPInboundChannel
*TCPInboundChannel: abc(abc)
excludeDistinguished (excludeDistinguished): 0
WASX7435W: Value 0 is converted to a boolean value of false.
unusedOnly (unusedOnly): 0
WASX7435W: Value 0 is converted to a boolean value of false.
List NamedEndPoints that can be used by a TCPInboundChannel
F (Finish)
C (Cancel)
Select [F, C]: [F] F
WASX7278I: Generated command line: AdminTask.listTCPEndPoints('[-excludeDistinguished false -unusedOnly false]')
WASX7015E: Exception running command: "AdminTask.listTCPEndPoints('-interactive')"; exception information:
com.ibm.websphere.management.cmdframework.CommandValidationException: ADMF0007E: target object is required.
Follow this link. It appears that you have not specified the target object that's why that error is coming.
I suggest use the following command as a starter
print AdminTask.listTCPEndPoints('-interactive')
Note: Instead of copying and pasting the command, type it on the command line. sometimes command editor does not take the command after pasting it directly.
Okay, I was able to fix the error. I was getting that error because as part of the application deployment script, I was copying few of my application jars to WebSphere's java/jre/lib/ext directory so that those are available in classpath. In one of those jar, I had bundled an IBM class (Base64Coder.class) which was required by a class in my jar and it was corrupting the WebSphere AdminTask utility. When I removed that Base64Coder.class from my jar, python script worked fine. I believe, the reason it corrupted WebSphere was that there was a duplication of the same class in the JVM as the class comes with IBM WebSphere installation and was present in AppServer/runtimes/com.ibm.ws.webservices.thinclient_7.0.0.jar

Show Python exception errors in Heroku log

I have a Heroku application written i Python. When it fails it does not log anything, but just stops code execution at the location of failure (it does not execute print statements just below) and then continues to run as nothing happens.
How can I display exception errors and traceback in the log? Is the behaviour different when exceptions are raised using the raise statement?
I have set the following in the config file:
DEBUG = True
PRESERVE_CONTEXT_ON_EXCEPTION = True
Tried with and without PRESERVE_CONTEXT_ON_EXCEPTION.
It depends on your environment.
Try to add these lines:
stream_handler = logging.StreamHandler()
stream_handler.setLevel(logging.INFO)
app.logger.addHandler(stream_handler)
Also, if you run the server with Gunicorn, you should add --log-level debug to your Procfile

How can I disable console messages when running maven commands?

I'm in the process of executing Maven commands to run tests in the console (MacOSX). Recently, development efforts have produced extraneous messages in the console (info, debug, warning, etc.) I'd like to know how to remove messages like this:
INFO c.c.m.s.c.p.ApplicationProperties - Loading application properties from: app-config/shiro.properties
I've used this code to remove messages from the dbunit tests:
ch.qos.logback.classic.Logger Logger = (ch.qos.logback.classic.Logger)LoggerFactory.getLogger("org.dbunit");
Logger.setLevel(Level. ERROR);
However, I'm unsure how to disable these additional (often verbose and irritating) messages from showing up on the console so that I can see the output more easily. Additional messages appear as above and these:
DEBUG c.c.m.s.c.f.dao.AbstractDBDAO - Adding filters to the Main Search query.
WARN c.c.m.s.c.p.JNDIConfigurationProperties - Unable to find JNDI value for name: xxxxx
INFO c.c.m.a.t.d.DatabaseTestFixture - * executing sql: xxxxx
The successful answer was:
SOLUTION: Solution to issue IS adding a 'logback-test.xml' file to the root of my test folder. I used the default contents (as instructed by the documentation - thanks #Charlie). Once file exists there, FIXED!

Resources