I try to implement NLog into my .NET Core Api web service.
I want to log to an Oracle database. All works well through an nlog.config XML file.
But the goal is to implement NLog config into appsettings.json and here problem occurs.
I get the error set in title:
LayoutRenderer cannot be found: 'aspnet-user-identity
My config file is like this :
"NLog": {
"autoReload": true,
"throwConfigExceptions": true,
"internalLogLevel": "info",
"internalLogFile": "c:/app/log/dev/internal-appsetting-nlog.txt",
"extensions": {
"NLog.Extensions.Logging": {
"assembly": [
"NLog.Extensions.Logging",
"NLog.Web.AspNetCore"
]
}
},
"variables": {
"var_logdir": "c:/app/log/dev"
},
"default-wrapper": {
"type": "AsyncWrapper",
"overflowAction": "Block"
},
"targets": {
"all-file": {
"type": "File",
"fileName": "${var_logdir}/nlog-all-${shortdate}.log",
"layout": {
"type": "JsonLayout",
"Attributes": [
{
"name": "timestamp",
"layout": "${date:format=o}"
},
{
"name": "level",
"layout": "${level}"
},
{
"name": "logger",
"layout": "${logger}"
},
{
"name": "message",
"layout": "${message:raw=true}"
},
{
"name": "properties",
"encode": false,
"layout": {
"type": "JsonLayout",
"includeallproperties": "true"
}
}
]
}
},
"db": {
"type": "Database",
"commandText": "INSERT INTO logtable (LOGLEVEL,LOGGER,MESSAGE,MACHINENAME,USERNAME,CALLSITE, THREADID,EXCEPTIONMESSAGE,STACKTRACE,SESSIONID) VALUES (:pLEVEL,:pLOGGER,:pMESSAGE,:pMACHINENAME, :pCALLSITE,:pTHREADID,:pEXCEPTIONMESSAGE,:pSTACKTRACE)",
"parameters": [
{
"name": "#pLEVEL",
"layout": "${level}"
},
{
"name": "#pLOGGER",
"layout": "${logger}"
},
{
"name": "#pMESSAGE",
"layout": "${message}"
},
{
"name": "#pMACHINENAME",
"layout": "${machinename}"
},
{
"name": "#pUSERNAME",
"layout": "${aspnet-user-identity}"
},
{
"name": "#pCALLSITE",
"layout": "${callsite:filename=true}"
},
{
"name": "#pTHREADID",
"layout": "${threadid}"
},
{
"name": "#pEXCEPTIONMESSAGE",
"layout": "${exception}"
},
{
"name": "#pSTACKTRACE",
"layout": "${stacktrace}"
},
{
"name": "#pSESSIONID",
"layout": "${aspnet-sessionid}"
}
],
"dbProvider": "Oracle.ManagedDataAccess.Client.OracleConnection, Oracle.ManagedDataAccess",
"connectionString": "xxxxxxxxxxxx"
}
},
"rules": [
{
"logger": "*",
"minLevel": "Trace",
"writeTo": "all-file"
},
{
"logger": "*",
"minLevel": "Trace",
"writeTo": "db"
},
{
"logger": "Microsoft.*",
"maxLevel": "Info",
"final": true
}
]
},
The internal debugger reports:
2019-10-09 16:48:48.6665 Info Adding target AsyncTargetWrapper(Name=all-file)
2019-10-09 16:48:48.7859 Warn Error when setting property 'Layout' on 'NLog.Targets.DatabaseParameterInfo' Exception: System.ArgumentException: LayoutRenderer cannot be found: 'aspnet-user-identity'. Is NLog.Web not included?
at NLog.Config.Factory`2.CreateInstance(String itemName)
at NLog.Layouts.LayoutParser.GetLayoutRenderer(ConfigurationItemFactory configurationItemFactory, String name)
at NLog.Layouts.LayoutParser.ParseLayoutRenderer(ConfigurationItemFactory configurationItemFactory, SimpleStringReader stringReader)
at NLog.Layouts.LayoutParser.CompileLayout(ConfigurationItemFactory configurationItemFactory, SimpleStringReader sr, Boolean isNested, String& text)
at NLog.Layouts.SimpleLayout.set_Text(String value)
at NLog.Internal.PropertyHelper.TryNLogSpecificConversion(Type propertyType, String value, Object& newValue, ConfigurationItemFactory configurationItemFactory)
at NLog.Internal.PropertyHelper.SetPropertyFromString(Object obj, String propertyName, String value, ConfigurationItemFactory configurationItemFactory)
Error occurs on ${aspnet-sessionid}. If I comment out both layout, everything works well.
I found different things on GitHub issue report but all I tried was a fail.
Could someone help?
The unknown aspnet-user-identity is probably an issue with your extensions:
"extensions": [
{ "assembly": "NLog.Extensions.Logging" },
{ "assembly": "NLog.Web.AspNetCore" }
],
Could you try the above suggestion?
P.S. Updated the wiki to include example of multiple "extensions"
Related
While running AWSFIS-Run-CPU-Stress i am getting below error:
Unable to start action, due to a platform mismatch between the specified document and the targeted instances. I am trying this in Windows EC2 instance
My Experiment script look like this(removed confidential server info):
{
"description": "Test CPU stress predefined SSM document",
"targets": {
"testInstance": {
"resourceType": "aws:ec2:instance",
"resourceArns": [
"arn:aws:ec2:region:123456789012:instance/instance_id"
],
"selectionMode": "ALL"
}
},
"actions": {
"runCpuStress": {
"actionId": "aws:ssm:send-command",
"parameters": {
"documentArn": "arn:aws:ssm:region::document/AWSFIS-Run-CPU-Stress",
"documentParameters": "{\"DurationSeconds\":\"120\"}",
"duration": "PT5M"
},
"targets": {
"Instances": "testInstance"
}
}
},
"stopConditions": [
{
"source": "aws:cloudwatch:alarm",
"value": "arn:aws:cloudwatch:region:123456789012:alarm:awsec2-instance_id-GreaterThanOrEqualToThreshold-CPUUtilization"
}
],
"roleArn": "arn:aws:iam::123456789012:role/AllowFISSSMActions",
"tags": {}
}
I've been trying to add filters to my Search Resource Availability api call following this page: Search resource availability API
No matter what I do I can't seem to filter by Organizational Unit.
Here's my http call body:
{
"Version": "3",
"IsWebApi": true,
"Requirement": {
"msdyn_fromdate": "2021-11-01T00:00:00Z",
"msdyn_todate": "2021-11-30T23:59:00Z",
"msdyn_remainingduration": 60,
"msdyn_duration": 60,
"#odata.type": "Microsoft.Dynamics.CRM.msdyn_resourcerequirement"
},
"Settings": {
"ConsiderSlotsWithProposedBookings": false,
"MovePastStartDateToCurrentDate": true,
"#odata.type": "Microsoft.Dynamics.CRM.expando"
},
"ResourceSpecification":{
"#odata.type": "Microsoft.Dynamics.CRM.expando",
"ResourceTypes#odata.type": "Collection(Microsoft.Dynamics.CRM.expando)",
"ResourceTypes": [
{
"#odata.type": "Microsoft.Dynamics.CRM.expando",
"value": "3"
}
],
"Constraints": {
"#odata.type": "Microsoft.Dynamics.CRM.expando",
"OrganizationalUnits#odata.type": "Collection(Microsoft.Dynamics.CRM.expando)",
"OrganizationalUnits":[
{
"#odata.type": "Microsoft.Dynamics.CRM.expando",
"value": "b2054232-a114-ec11-b6e7-000d3a842ab8"
}
]
}
}
}
And here's the response I get:
{
"#odata.context": "https://orga215da53.api.crm3.dynamics.com/api/data/v9.2/$metadata#Microsoft.Dynamics.CRM.msdyn_SearchResourceAvailabilityResponse",
"TimeSlots": [],
"Resources": [],
"Related": {
"#odata.type": "#Microsoft.Dynamics.CRM.expando",
"TimeSlots#odata.type": "#Collection(Microsoft.Dynamics.CRM.crmbaseentity)",
"TimeSlots": [],
"Resources#odata.type": "#Collection(Microsoft.Dynamics.CRM.crmbaseentity)",
"Resources": []
},
"Exceptions": {
"#odata.type": "#Microsoft.Dynamics.CRM.expando"
}
}
But i KNOW that that organization unit exists in CRM.
I tried changing the odata.type to the actual Organization Unit CRM type (msdyn_organizationalunit) but that just gives me an error (An error occurred while validating input parameters: System.ArgumentNullException: Value cannot be null)
What is it that I'm doing wrong?
Thanks!
Good day,
I'm not sure but maybe "Constraints" should be outside "ResourceSpecification" like:
{
"Version": "3",
"IsWebApi": true,
"Requirement": {
"msdyn_fromdate": "2021-11-01T00:00:00Z",
"msdyn_todate": "2021-11-30T23:59:00Z",
"msdyn_remainingduration": 60,
"msdyn_duration": 60,
"#odata.type": "Microsoft.Dynamics.CRM.msdyn_resourcerequirement"
},
"Settings": {
"ConsiderSlotsWithProposedBookings": false,
"MovePastStartDateToCurrentDate": true,
"#odata.type": "Microsoft.Dynamics.CRM.expando"
},
"ResourceSpecification":{
"#odata.type": "Microsoft.Dynamics.CRM.expando",
"ResourceTypes#odata.type": "Collection(Microsoft.Dynamics.CRM.expando)",
"ResourceTypes": [
{
"#odata.type": "Microsoft.Dynamics.CRM.expando",
"value": "3"
}
]
},
"Constraints": {
"#odata.type": "Microsoft.Dynamics.CRM.expando",
"OrganizationalUnits#odata.type": "Collection(Microsoft.Dynamics.CRM.expando)",
"OrganizationalUnits":[
{
"#odata.type": "Microsoft.Dynamics.CRM.expando",
"value": "b2054232-a114-ec11-b6e7-000d3a842ab8"
}
]
}
}
I have created a basic state machine that runs a lambda and then uses the output of that lambda to decide a choice. However, I have not been able to receive the output from the lambda function because it keeps returning a null payload. I have tried running the lambda alone from the lambda console and it runs fine (including with the expected return). However, within the step function, the task at least, is returning null for the Payload output.
Here is the definition of my state-machine:
{
"StartAt": "ValidateWorkcellConfigTask",
"States": {
"ValidateWorkcellConfigTask": {
"Next": "ConfigValidationTypeChoiceState",
"Parameters": {
"FunctionName": "ValidateWorkcellConfig",
"InvocationType": "Event",
"Payload.$": "$"
},
"OutputPath": "$",
"Type": "Task",
"Resource": "arn:aws:states:::lambda:invoke",
"TimeoutSeconds": 15
},
"ConfigValidationTypeChoiceState": {
"Type": "Choice",
"Comment": "Forwards a VALID workflow config to the Provisioning Workflow or Relays the INVALID workflow config for logging",
"Choices": [
{
"Variable": "$.uuid",
"StringEquals": "SEA90-1",
"Next": "endState"
},
{
"Variable": "$.validConfig",
"StringEquals": "SEA90-1",
"Next": "SuccessRelayTask"
}
]
},
"endState": {
"Type": "Pass",
"End": true
},
"SuccessRelayTask": {
"End": true,
"Parameters": {
"FunctionName": "StatusRelayHandler",
"InvocationType": "Event",
"Payload.$": "$"
},
"OutputPath": "$",
"Type": "Task",
"Resource": "arn:aws:states:::lambda:invoke",
"ResultPath": "$",
"TimeoutSeconds": 15
}
}
}
And here is the output of the lambda task execution:
{
"name": "ValidateWorkcellConfigTask",
"output": {
"Payload": null,
"SdkHttpMetadata": {
"AllHttpHeaders": {
"x-amzn-Remapped-Content-Length": [
"0"
],
"Connection": [
"keep-alive"
],
"x-amzn-RequestId": [
"4452a8d2-e607-4ae6-943c-9478b0f59ce0"
],
"Content-Length": [
"0"
],
"Date": [
"Sat, 16 Jan 2021 09:22:48 GMT"
],
"X-Amzn-Trace-Id": [
"root=1-6002b068-52fb3d1f60f20d3e10804f96;sampled=0"
]
},
"HttpHeaders": {
"Connection": "keep-alive",
"Content-Length": "0",
"Date": "Sat, 16 Jan 2021 09:22:48 GMT",
"x-amzn-Remapped-Content-Length": "0",
"x-amzn-RequestId": "4452a8d2-e607-4ae6-943c-9478b0f59ce0",
"X-Amzn-Trace-Id": "root=1-6002b068-52fb3d1f60f20d3e10804f96;sampled=0"
},
"HttpStatusCode": 202
},
"SdkResponseMetadata": {
"RequestId": "4452a8d2-e607-4ae6-943c-9478b0f59ce0"
},
"StatusCode": 202
},
"outputDetails": {
"truncated": false
}
}
Notice how the payload is null... that is causing the next task to fail because it receives a null input. I've already played around with OutputPath, ResultPath, and InputPath but have never been able to return something from the lambda task.
The lambda itself is written in Java and return a String. It implements this interface:
... implements RequestHandler<WorkcellConfig, String>
I think the problem that you have may be due to the Invocation Type, you set it as event (asynchronously) so you give no time to the lambda function to return the result payload. Try changing it to RequestResponse to run it synchronously (this is the default type, so you can omit this parameter).
You can check more details about Invocation Type here.
The code should look like this:
{
"StartAt": "ValidateWorkcellConfigTask",
"States": {
"ValidateWorkcellConfigTask": {
"Next": "ConfigValidationTypeChoiceState",
"Parameters": {
"FunctionName": "ValidateWorkcellConfig",
"Payload.$": "$"
},
"OutputPath": "$",
"Type": "Task",
"Resource": "arn:aws:states:::lambda:invoke",
"TimeoutSeconds": 15
},
"ConfigValidationTypeChoiceState": {
"Type": "Choice",
"Comment": "Forwards a VALID workflow config to the Provisioning Workflow or Relays the INVALID workflow config for logging",
"Choices": [
{
"Variable": "$.uuid",
"StringEquals": "SEA90-1",
"Next": "endState"
},
{
"Variable": "$.validConfig",
"StringEquals": "SEA90-1",
"Next": "SuccessRelayTask"
}
]
},
"endState": {
"Type": "Pass",
"End": true
},
"SuccessRelayTask": {
"End": true,
"Parameters": {
"FunctionName": "StatusRelayHandler",
"Payload.$": "$"
},
"OutputPath": "$",
"Type": "Task",
"Resource": "arn:aws:states:::lambda:invoke",
"ResultPath": "$",
"TimeoutSeconds": 15
}
}
}
I am calling API and getting below output but from the output and i want to find the key based on value input and my input value is "vpc-tz" how to achieve this in ansible using json_query?
{
"json": {
"allScopes": [
{
"
"clusters": {
"clusters": [
{
"cluster": {
"clientHandle": "",
"type": {
"name": "ClusterComputeResource"
},
"universalRevision": 0,
"vsmUuid": "423B1819-9495-4F10-A96A-6D8284E51B29"
}
}
]
},
"controlPlaneMode": "UNICAST_MODE",
"description": "",
"extendedAttributes": [
],
"id": "vdnscope-6",
"isTemporal": false,
"isUniversal": false,
"name": "vpc-tz",
"nodeId": "85e0073d-0e5a-4f04-889b-42df771aebf8",
"objectId": "vdnscope-6",
"objectTypeName": "VdnScope",
"revision": 0,
"type": {
"name": "VdnScope"
},
"universalRevision": 0,
"virtualWireCount": 0,
"vsmUuid": "423B1819-9495-4F10-A96A-6D8284E51B29"
},
]
}
}
Here is a query which works:
json.allScopes[?name=='vpc-tz'].name
I am implementing my Alexa Home Skill using AWS Lambda.
Given the following request I receive when I try to detect new devices on Alexa Skil test page:
{directive={header={namespace=Alexa.Discovery, name=Discover, payloadVersion=3, messageId=0160c7e7-031f-47ee-a1d9-a23f38f87a9e}, payload={scope={type=BearerToken, token=...}}}}
I respond with the following:
{
"event": {
"payload": {
"endpoints": [
{
"displayCategories": [
"SMARTPLUG"
],
"capabilities": [
{
"type": "AlexaInterface",
"interface": "Alexa",
"version": "3"
},
{
"type": "AlexaInterface",
"interface": "Alexa.PowerController",
"version": "3",
"properties": {
"retrievable": true,
"supported": [
{
"name": "powerState"
}
],
"proactivelyReported": true
}
},
{
"type": "AlexaInterface",
"interface": "Alexa.EndpointHealth",
"version": "3",
"properties": {
"retrievable": true,
"supported": [
{
"name": "connectivity"
}
],
"proactivelyReported": true
}
}
],
"manufacturerName": "mirko.io",
"endpointId": "ca84ef6d-53b1-430a-8a5e-a62f174eac5e",
"description": "mirko.io forno (id: ca84ef6d-53b1-430a-8a5e-a62f174eac5e)",
"friendlyName": "forno"
}
]
},
"header": {
"payloadVersion": "3",
"namespace": "Alexa.Discovery",
"name": "Discover.Response",
"messageId": "c0555cc8-ad7a-4377-b310-9de9b9ab6282"
}
}
}
Despite that, for some reasons Alexa answers that it did not find any new device.
I may be mistaken but I am pretty sure it used to work before I decided to add the Alexa.EndpointHealth interface.
Your response object looks right to me, except the extra "endpoint" field.
"endpoint": {
"endpointId": "INVALID",
"scope": {
"type": "BearerToken",
"token": "INVALID"
}
}
There's no such field in the Alexa.Discovery documentation. Try removing it and see if it resolves the issue.