NLog config settings renderer not working as expected - nlog

Just uploaded a test case app - https://github.com/lsfera/NLog-Demo-cases/tree/master/Net5
I have a configuration section in my appsettings to provide environment specific parameters.
"LoggingContext": {
..
"ApplicationName": "cool-app",
"SyslogUrl": "syslog.server.url"
}
Everything works fine - also the configSetting layout renderer part - except it doesn't work as (I) expected.
"targets": {
"file": {
"type": "AsyncWrapper",
"target": {
"wrappedFile": {
"type": "File",
"fileName": "${configsetting:item=LoggingContext.ApplicationName}.log"
.......
File name is correctly replaced - as expected - resulting in "cool-app.log".
But when it comes to syslog section:
"syslog": {
...
"messageSend": {
"protocol": "tcp",
"tcp": {
"server": "${configsetting:item=LoggingContext.SyslogUrl}"
...
server is left in raw format - "${configsetting:item=LoggingContext.SyslogUrl}"
Same issue with target of type "Http" with "URL" parameter "${configsetting:item=LoggingContext.AlertServiceUrl}"
What's wrong in this configuration?
Example project contains the nlog.config xml version - too convenience

NLog.Targets.Syslog ver. 6.0.3 has been released to nuget with Layout-support for Server-property.
NLog.Targets.HTTP ver. 1.0.16 has been released to nuget with Layout-support for Headers (Right now there is a bug so one have to explict assign Authorization="" on the target).
<target type="HTTP"
name="ws"
Method='POST'
URL="https://log-api.eu.newrelic.com/log/v1"
ContentType='application/json'
Accept='application/json'
Authorization=''>
<header name="X-License-Key" value="${environment:LICENSE_KEY}"/>
</target>

Related

How can I step into library code using the VS Code debugger in a Typescript/Node.js project?

I have a Node.js project written in Typescript with the following dependency:
"dependencies": {
...
"#uniswap/smart-order-router": "^2.5.15",
From this library package I import some stuff in my project:
import { AlphaRouter, ... } from '#uniswap/smart-order-router'
And then use it like this:
const routeToRatioResponse: SwapToRatioResponse = await router.routeToRatio(
token0Balance,
token1Balance,
p,
{
ratioErrorTolerance: new Fraction(5, 100),
maxIterations: 1,
},
{
swapOptions: {
recipient: wallet.address,
slippageTolerance: new Percent(5, 100),
deadline: deadlineValue
},
addLiquidityOptions: {
recipient: wallet.address
}
}
)
I have a breakpoint set on that first line above, at the call to router.routeToRatio(). When using the VS Code debugger, execution stops correctly at that line. But then when I click 'Step Into', I do not step into this function at all but instead go to the line after this whole function call.
The library project is written in Typescript. The code is here: https://github.com/Uniswap/smart-order-router. Note that the tsconfig.json for it has inlineSourceMap as true here: https://github.com/Uniswap/smart-order-router/blob/main/tsconfig.json#L9.
I don't seem to have the TS source for the library project in my node_modules dir. When I Ctrl-click on the function name, VS Code takes me to ./node_modules/#uniswap/smart-order-router/build/main/src/routers/alpha-router/alpha-router.d.ts (which has no implementation code, only a class declaration), not to a file called alpha-router.ts. Digging around under node_modules I seem not to have that file.
This answered question mentions the library project should have the sourceRoot set in the tsconfig.json, which it does not. I do not own the library project though, so I can't change anything there.
(Edit 1) Here's my launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "foo",
"type": "node",
"program": "${workspaceFolder}/foo/src/index.ts",
"request": "launch",
"skipFiles": [
"<node_internals>/**"
],
"preLaunchTask": "tsc: build - foo/tsconfig.json",
"outFiles": [
"${workspaceFolder}/**/*.js"
],
"cwd": "${workspaceFolder}/foo"
}
]
}
(Edit 2): Per the comments so far, I now have the dependencies I'm interested in debugging installed (in the npm install sense) as local folders. package.json looks like this:
"dependencies": {
...
"#uniswap/smart-order-router": "file:../smart-order-router",
...
tsconfig.json has "allowJs" missing. I had to install some of the dependency's dependencies directly in my package.json. The code now builds with tsc without errors (without having to change any paths to imports in the TS sources), but now the debugger is completely broken.
The debugger stops at a breakpoint on the very first line of my index.ts and will step over lines ok for a bit but then execution stops here without any error: node_modules/antlr4ts/index.js
The only thing on the debug console in VSC is:
/home/e/.nvm/versions/node/v14.15.4/bin/node ./node_modules/antlr4ts/index.js

SPFX Package always referring content or resources from localhost instead from CDN

Can someone please let me know from where I can change this configuration so that it should refer from the CDN path instead of localhost
Below is my package-solution.json
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/package-solution.schema.json",
"solution": {
"name": "mega-menu-sp-fx-client-side-solution",
"id": "8f49d75c-5a49-4657-b81b-0290f239350f",
"version": "10.0.0.0",
"includeClientSideAssets": true,
"skipFeatureDeployment": true,
"isDomainIsolated": false,
"features": [
{
"title": "Application Extension - Deployment of custom action.",
"description": "Deploys a custom action with ClientSideComponentId association",
"id": "0d2345df-2a49-4ce9-ba2d-bee7ad3e7a02",
"version": "10.0.0.0",
"assets": {
"elementManifests": [
"elements.xml",
"clientsideinstance.xml"
]
}
}
]
},
"paths": {
"zippedPackage": "solution/mega-menu-sp-fx.sppkg"
}
}
Below is my write-manifest.json
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/write-manifests.schema.json",
"cdnBasePath": "https://Mytenant.sharepoint.com/sites/MyTechTheme/MenuFiles"
}
I tried to figure out whats the issue. For publishing instead of gulp package-solution --ship I had used gulp package-solution so unless and until we don't mention --ship it wont take the references for CDN
So for deploying the package in SPO we need to use gulp bundle --ship and gulp package-solution --ship
As per this thread, to load SPFx assets from a CDN or SharePoint library, set the value of "includeClientSideAssets" to false.
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/package-solution.schema.json",
"solution": {
...
"includeClientSideAssets": false,
...
}
}

Does Serilog console write to the IIS log file if stdoutLogEnabled is true?

I am using Core 2.2 with Serilog via a Console sink. Locally, this works great via Kestrel. My console opens and I get tons of logs. This changes when I go to IIS. If I flip stdoutLogEnabled to true, and I create a logs directory and give it "Everyone - modify" ACL I do actually get a file, and I get output:
Hosting environment: Production
Content root path: C:\inetpub\wwwroot\mysites\myapp-api
Application started. Press Ctrl+C to shut down.
But then that is it. My app is throwing 500 errors but nothing gets logged. Locally, in my console window I can see all of those logs. If Serilog logs to console via Stdout then what is the issue?
Also, I tried to add the file sink and configure it, but I could not get Serilog to produce a file. I think maybe I got the path wrong? I assume if I get the above log, ACLs aren't the issue and Serilog should be able to write. But that is another issue.
If it matters I HAVE enabled <AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel> on my web project.
Serilog Config:
"Serilog": {
"MinimumLevel": {
"Default": "Warning",
"Override": {
"Microsoft": "Warning",
"System": "Warning",
"Microsoft.AspNetCore.Authentication": "Information"
}
},
// Console logger. Use Web.Config to see this.
"WriteTo:ConsoleSublogger": {
"Name": "Logger",
"Args": {
"configureLogger": {
"WriteTo": [
{
"Name": "LiterateConsole",
"Args": {
"outputTemplate": "DevConf [{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}{NewLine}",
"theme": "Code"
}
}
]
},
"restrictedToMinimumLevel": "Debug"
}
},
"Enrich": [
"FromLogContext",
// Add full exception details using Serilog.Exceptions https://github.com/RehanSaeed/Serilog.Exceptions.
"WithExceptionDetails",
// Add the username and machine name to the logs using Serilog.Enrichers.Environment https://github.com/serilog/serilog-enrichers-environment.
"WithEnvironmentUserName",
"WithMachineName",
// Add the process ID and name to the logs using Serilog.Enrichers.Process https://github.com/serilog/serilog-enrichers-process.
"WithProcessId",
"WithProcessName",
// Add the current thread ID to the logs using Serilog.Enrichers.Thread https://github.com/serilog/serilog-enrichers-thread.
"WithThreadId"
],
"Properties": {
"Application": "myapp-api"
}
},

How to debug AWS Lambda Node.js locally using serverless module?

I am completely new to AWS and serverless etc. To speed up development I would like the ability to debug my application locally.
Following this article Running and Debugging AWS Lambda functions locally I have attempted to achieve just that.
In Visual Studio Code when I run the debug configuration, the application exits instantly without error (A break-point is set on the declaration and initialisation of the 'content' variable). I am not sure I have the function name correct. I am trying to enter at the main 'handler' function defined in 'index.js' as:
exports.handler = (event, context, callBack) =>
{
let bIsPostRequest = false, bIsPutRequest = false, bIsGetRequest = false, bIsDelRequest = false;
let content = "";
...
Here is my 'launch.json' configuration file:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Debugger",
"program":
"${workspaceFolder}\\node_modules\\serverless\\bin\\serverless",
"args":[
"invoke",
"local",
"-f",
"index.handler", // function name
"--data",
"{}"
],
"outFiles": [
"${workspaceFolder}\\index.js"
]
}
]
}
Also, I am not 100% certain on the definition of 'outfiles' in the configuration. I have come to the conclusion it is the file(s) I am trying to debug, however if this is the case 'outfiles' does not seem a fitting name to me.
The local environment I am working in is a windows one.
After coming across this post I managed to get the debugger working. Here is the configuration to match my needs:
const lambdaLocal = require('lambda-local');
var lambdaFunc = require("./index.js");
lambdaLocal.execute({
lambdaFunc: lambdaFunc,
lambdaHandler: "handler",
event: {
context: {
"resource-path": "/products",
"http-method": "GET"
},
"body-json": {
name : "ProductA"
}
}
}).then(function(done) {
console.log(done);
}).catch(function(err) {
console.log(err);
});
I saved this file as 'debugLocal.js' in my main working directory. The launch.json file now looks as follows:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Debugger",
"program": "${workspaceFolder}\\debugLocal.js"
}
]
}
So far everything appears to be replicated fairly well. One thing to note is the file paths on includes had to be changed slightly i.e. require("./js/inc/globalDefines.js"); instead of require("js/inc/globalDefines.js");

Chef overwrite default attributes of a cookbook

The git cookbook has an error in the url that it uses to download the appropriate version. The url is set in the attributes file as a default attribute so I figured I could just overwrite the url with something static but it does not work. Here is the code from the git cookbook:
case node['platform_family']
when 'windows'
default['git']['version'] = '2.8.1'
if node['kernel']['machine'] == 'x86_64'
default['git']['architecture'] = '64'
default['git']['checksum'] = '5e5283990cc91d1e9bd0858f8411e7d0afb70ce26e23680252fb4869288c7cfb'
else
default['git']['architecture'] = '32'
default['git']['checksum'] = '17418c2e507243b9c98db161e9e5e8041d958b93ce6078530569b8edaec6b8a4'
end
default['git']['url'] = 'https://github.com/git-for-windows/git/releases/download/v%{version}.windows.1/Git-%{version}-%{architecture}-bit.exe'
The cookbook is being included as a dependency in my metadata.rb file and used as a resource in my recipe. It is not part of the runlist. I've tried overwriting the url in my role file like so
"name": "web",
"description": "Web Server Role.",
"json_class": "Chef::Role",
"default_attributes": {
"chef_client": {
"interval": 300,
"splay": 60
},
"git": {
"url": "a test string"
}
},...
That did not work, so I tried adding it to the attributes file of my recipe as a default value, and when that did not work, I tried the override! method which still did not work.
I think the problem is due to the fact that the attribute does not exist when I have declared it, and it gets overwritten by the git recipe.
I don't know how to get around that.
Use override_attributes instead of default_attributes:
"name": "web",
"description": "Web Server Role.",
"json_class": "Chef::Role",
"default_attributes": {
"chef_client": {
"interval": 300,
"splay": 60
}
},
"override_attributes": {
"git": {
"url": "a test string"
}
},...

Resources