I want to connect Azure Event hub using NLog.Extensions.AzureEventHub because its part of Nlog configuration, But not sure how do I pass the target correctly I am getting error but cant understand reason because I am passing the string , I check the online Nlog documentation but its only providing the Xml settings. Could you please give example app settings for Nlog Azure Eventhub taget (C# .net core 6.0)
NLog.Extensions.AzureStorage
This is my app settings
"NLog":{
"internalLogLevel":"Info",
"internalLogFile":"c:\\temp\\internal-nlog.txt",
"extensions": [
{ "assembly": "NLog.Extensions.Logging" },
{ "assembly": "NLog.Web.AspNetCore" },
{ "assembly": "NLog.Extensions.AzureEventHub" }
],
"targets": {
"allfile": {
"type": "File",
"fileName": "c:\\temp\\nlog-all-${shortdate}.log",
"layout": "${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}"
},
"ownFile-web": {
"type": "File",
"fileName": "c:\\temp\\nlog-own-${shortdate}.log",
"layout": "${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}|url: ${aspnet-request-url}|action: ${aspnet-mvc-action}"
},
"eh": {
"type": "AzureEventHub",
"credentials": {
"name": "eventhub1",
"connectionString": "Endpoint=sb://eventhubnp198007.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=4z/JbjHp7UqxCWPD343434343GZbJpfG5E="
},
"layout": "${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}|url: ${aspnet-request-url}|action: ${aspnet-mvc-action}"
}
},
"rules":[
{
"logger":"*",
"minLevel":"Trace",
"writeTo":"allfile"
},
{
"logger":"Microsoft.*",
"maxLevel":"Info",
"final":"true"
},
{
"logger":"*",
"minLevel":"Trace",
"writeTo":"ownFile-web"
}
]
}
Error
> 2022-08-23 12:59:10.0781 Error AzureEventHub(Name=eh): Failed to
> create EventHubClient with connectionString= to EventHubName=.
> Exception: System.ArgumentException: Value cannot be an empty string.
> (Parameter 'connectionString') at
> Azure.Core.Argument.AssertNotNullOrEmpty(String value, String name)
> at
> Azure.Messaging.EventHubs.Producer.EventHubProducerClient..ctor(String
> connectionString, String eventHubName, EventHubProducerClientOptions
> clientOptions) at
> NLog.Targets.EventHubTarget.EventHubService.Connect(String
> connectionString, String eventHubName, String serviceUri, String
> tenantIdentity, String resourceIdentity, String clientIdentity) at
> NLog.Targets.EventHubTarget.InitializeTarget()
Not sure why you have added the "credentials"-section, but I think it will work if you just remove it. Since it also doesn't exist in the xml-config:
"eh": {
"type": "AzureEventHub",
"eventHubName": "eventhub1",
"connectionString": "Endpoint=sb://eventhubnp198007.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=4z/JbjHp7UqxCWPD343434343GZbJpfG5E=",
"layout": "${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}|url: ${aspnet-request-url}|action: ${aspnet-mvc-action}"
}
The Json-configuration tries to map 1-to-1 with the Xml-configuration. See also: https://github.com/NLog/NLog.Extensions.Logging/wiki/NLog-configuration-with-appsettings.json
The only place where Json and Xml really divert is when handling "list of items". Where Json must specify the actual collection-name, and Xml supports node-items.
It is a good idea to use "throwConfigExceptions": true as it will quickly reveal invalid configuration. Especially when using NLog v5.
Btw. if you want the target "eh" to be used, then you must include it in the "writeTo":. Ex:
{
"logger":"*",
"minLevel":"Trace",
"writeTo":"eh, ownFile-web"
}
Related
I'm using nlog for logging, and c# activity for spans with contexts such as traceparent / traceid.
I am adding an optional custom property to the activity, like this: activity.SetCustomProperty(customProperty.Key,customProperty.Value))
I would like to add the value to a log record.
However, I'm unsure on the correct configuration for NLog.
When configuring NLog layouts, you can set attribute layouts.
One of the layout renderers is the ActivityTraceLayoutRenderer.
Here is how I'm trying to configure the ActivityTraceLayoutRenderer, assuming the CustomProperty configured on the trace is "ReservationId":
"layout": {
"type": "JsonLayout",
"attributes": [
{
"name": "timestamp",
"layout": "${date:format=yyyy-MM-ddTHH\\:mm\\:ss.ffffff}"
},
{
"name": "traceId",
"layout": "${activity:property=TraceId}"
},
{
"name": "reservationId",
"layout": "${activity:{property=CustomProperty,item=ReservationId}}"
}
]
}
However, the resulting logs look... weird:
{ "timestamp": "2022-08-08T14:39:38.000840", "reservationId": "}" }
Have been following a post which details the steps required for setting up React with C#. However, I am being presented with the following error everytime I try to compile a React application:
Support for the experimental syntax 'classProperties' isn't currently enabled
onChange = (e) => {
this.setState({ value: parseInt(e.currentTarget.value, 10) });
};
The error message outlines:
Add #babel/plugin-proposal-class-properties (https://git.io/vb4SL) to the 'plugins' section of your Babel config to enable transformation. If you want to leave it as-is, add #babel/plugin-syntax-class-properties (https://git.io/vb4yQ) to the 'plugins' section to enable parsing.
Therefore, I altered my package.json to suit:
{
"name": "Test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "webpack --config=Scripts/React/config/webpack.config.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"#babel/core": "^7.10.3",
"#babel/plugin-proposal-class-properties": "^7.10.1",
"#babel/preset-react": "^7.10.1",
"#babel/preset-env": "^7.2.3",
"babel-preset-react": "^6.23.0",
"babel-loader": "^8.1.0",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"webpack": "^4.43.0",
"webpack-cli": "^3.3.12"
},
"dependencies": {
"react-countup": "^4.3.3",
"react-router": "^5.2.0",
"react-svg-gauge": "^1.0.10",
"reactstrap": "^8.5.1",
"recharts": "^1.8.5"
},
"babel": {
"presets": [
"#babel/preset-env",
"#babel/preset-react"
],
"plugins": [
"#babel/plugin-proposal-class-properties"
]
}
}
Despite this, I am still receiving the same error. Does anyone have any ideas as to how I can mitigate this issue?
Try this , possible duplicate Support for the experimental syntax 'classProperties' isn't currently enabled
"plugins": [
[
"#babel/plugin-proposal-class-properties",
{
"loose": true
}
]
]
From studying Serilog.Sinks.AzureTableStorage I have the following
In Main
var configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.Build();
var logger = new LoggerConfiguration()
.ReadFrom.Configuration(configuration) // the error happens here
.CreateLogger();
logger.Information("Hello, world!");
In appsetttings.json ( with different connection string)
"Serilog": {
"Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.AzureTableStorage" ],
"MinimumLevel": "Debug",
"WriteTo": [
{ "Name": "Console" },
{
"Name": "File",
"Args": { "path": "%TEMP%\\Logs\\serilog-configuration-sample.txt" }
},
{
"Name": "AzureTableStorage",
"Args": {
"storageTableName": "mystoragetable",
"connectionString": "myconnectionstring"
}
}
],
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ],
"Destructure": [
{
"Name": "With",
"Args": { "policy": "Sample.CustomPolicy, Sample" }
},
{
"Name": "ToMaximumDepth",
"Args": { "maximumDestructuringDepth": 4 }
},
{
"Name": "ToMaximumStringLength",
"Args": { "maximumStringLength": 100 }
},
{
"Name": "ToMaximumCollectionCount",
"Args": { "maximumCollectionCount": 10 }
}
],
"Properties": {
"Application": "Sample"
}
}
I see in the debug output yet no data gets logged to the storage table.
Exception thrown: 'System.InvalidCastException' in System.Private.CoreLib.dll
An unhandled exception of type 'System.InvalidCastException' occurred in System.Private.CoreLib.dll
Invalid cast from 'System.String' to 'Serilog.Core.IDestructuringPolicy'.
[Update]
If I use a very simple config as per the ReadMe.Md in GitHub, I get the same error.
[Update]
I copied in the code from Kennyzx link. The error has changed to
System.InvalidCastException
HResult=0x80004002
Message=Invalid cast from 'System.String' to 'Serilog.Core.ILogEventFilter'.
Source=System.Private.CoreLib
I decided to try upgrading the serilog-settings-configuration sample project to .netcore2.1 and thus asked this question
After a few hours I came to the conclusion that serilog-settings-configuration s is not compatible with dotnetcore 2.1
I try to set up a new .NET Core 2.1 Console project called UseSerilog and I can reproduce the issue.
After I remove the Destructure and Filter sections from the configuration then the app begins to work.
Then I check the source code of the Serilog.Settings.Configuration package, I find this commit, and I come to conclusion that you need to write some code in order to make it work like this way.
For the below configuration, you are expected to write a CustomPolicy class in the "Sample" namespace that implements IDestructuringPolicy.
{
"Name": "With",
"Args": { "policy": "Sample.CustomPolicy, Sample" }
}
If you remove this, and leave Destructure as below, it is working.
"Destructure": [
{
"Name": "ToMaximumDepth",
"Args": { "maximumDestructuringDepth": 3 }
},
{
"Name": "ToMaximumStringLength",
"Args": { "maximumStringLength": 10 }
},
{
"Name": "ToMaximumCollectionCount",
"Args": { "maximumCollectionCount": 5 }
}
]
Hope this finding helps you.
I am trying to deploy a virtual machine in azure via JSON using as much as possible JSON templates and parameters, when i try to generate an extension for the VM i get the error:
"VMExtensionProvisioningError"
with the message:
"Failed to decode, decrypt, and deserialize the protected settings string. Error Message: Keyset does not exist"
And i dont know what this stands for.
{
"apiVersion": "2017-12-01",
"dependsOn": [
"[concat('Microsoft.Compute/virtualMachines/', parameters('virtualMachineName'))]"
],
"location": "[resourceGroup().location]",
"name": "[concat(parameters('virtualMachineName'),'/CustomScriptExtension')]",
"properties": {
"publisher": "Microsoft.Compute",
"type": "CustomScriptExtension",
"typeHandlerVersion": "1.7",
"autoUpgradeMinorVersion" : true,
"settings": {
"fileUris": [
"https://{storageAccountName}.blob.core.windows.net/scripts/{scriptName}"
],
"commandToExecute": "[concat('powershell -ExecutionPolicy Unrestricted -file "{scriptName}" ')]"
},
"protectedSettings": { "storageAccountName": "[parameters('storageAccountName')]" }
},
"type": "Microsoft.Compute/virtualMachines/extensions"
},
What i am trying is to execute a script obtained from a blob in Azure.
What i am doing wrong?
I have a azure data factory project.
I read the docs https://learn.microsoft.com/en-us/azure/data-factory/data-factory-use-custom-activities to add custom activities to one of my pipelines.
in the documentation said that you have to zip the dlls of your class library that represent the custom activities, and storage this zip in a azure blob.
and the definition of the pipeline are:
{
"name": "LoadFromOnerxSalesInvoicesRaw",
"properties": {
"description": "Test Deserialize Sales Invoices Raw",
"activities": [
{
"type": "DotNetActivity",
"typeProperties": {
"assemblyName": "BICodeActivities.dll",
"entryPoint": "BICodeActivities.Activities.OneRx.DeserializeSalesInvoiceToLines",
"packageLinkedService": "biCABlobLS",
"packageFile": "bi-activities-container/BICodeActivities.zip",
"extendedProperties": {
"SliceStart": "$$Text.Format('{0:yyyyMMddHH-mm}', Time.AddMinutes(SliceStart, 0))"
}
},
"inputs": [
{
"name": "o-staging-onerx-salesInvoices"
}
],
"outputs": [
{
"name": "o-staging-onerx-salesInvoicesLines"
}
],
"policy": {
"timeout": "00:30:00",
"concurrency": 2,
"retry": 3
},
"scheduler": {
"frequency": "Day",
"interval": 1
},
"name": "DeserializeSalesInvoiceToLines",
"linkedServiceName": "biBatchLS"
},
{
"type": "DotNetActivity",
"typeProperties": {
"assemblyName": "BICodeActivities.dll",
"entryPoint": "BICodeActivities.Activities.OneRx.DeserializeSalesInvoiceToDiscounts",
"packageLinkedService": "biCABlobLS",
"packageFile": "bi-activities-container/BICodeActivities.zip",
"extendedProperties": {
"SliceStart": "$$Text.Format('{0:yyyyMMddHH-mm}', Time.AddMinutes(SliceStart, 0))"
}
},
"inputs": [
{
"name": "o-staging-onerx-salesInvoices"
}
],
"outputs": [
{
"name": "o-staging-onerx-salesInvoicesDiscounts"
}
],
"policy": {
"timeout": "00:30:00",
"concurrency": 2,
"retry": 3
},
"scheduler": {
"frequency": "Day",
"interval": 1
},
"name": "DeserializeSalesInvoiceToDiscounts",
"linkedServiceName": "biBatchLS"
}
],
"start": "2017-04-26T09:20:00Z",
"end": "2018-04-26T22:30:00Z"
}
}
When set up this pipeline in my visual studio project and build i get an error "BICodeActivities.zip is not found in the solution".
I have to zip the dlls and add manually to the solution?, or i need to do something else?
I'm assuming you have the custom acitivites as class library in the same solution as your data factory project.
If so, you simply need to reference the class library project in the data factory project. Right click > Add > Reference. Select the library project.
Once done, when you build the solution Visual Studio will handle the zipping of the DLL's for you and also add the ZIP folder as a dependency which will show in the publishing wizard to be deployed to the blob storage linked service.
For further support check out this blog post.
https://www.purplefrogsystems.com/paul/2016/11/creating-azure-data-factory-custom-activities/
Hope this helps.