Use Sub Logger from Serilog in app.config - app-config

I am using app.config to write SubLogger.
I am able to do it using code.
What will syntax to do below:
.WriteTo.Logger(c =>
c.Filter.ByIncludingOnly(
Matching.WithProperty("Category", "Test"))
.WriteTo.File("logheadertest123.txt"))
and while logging:
LogContext.PushProperty("Category", value: category);
log.Write(entry);
How can i achieve this in Serilog using app.config?

Related

IdentityServer4 Version="4.1.1" MTLS configuration services.AddAuthentication().AddCertificate not working

Problem with Startup.cs setup, according to documentation I should add
services.AddAuthentication()
.AddCertificate(options =>
{
options.AllowedCertificateTypes = CertificateTypes.All;
options.RevocationMode = X509RevocationMode.NoCheck;
});
But I got error:
'AuthenticationBuilder' does not contain a definition for
'AddCertificate' and there is no extension method 'AddCertificate'.
In samples code setup IdentityServer(HOST)/ConsoleMTLSClient it works .
You have to add the Microsoft.AspNetCore.Authentication.Certificate NuGet package.

SQL Server connection string in Appsettings.json + .net Core 3.1

I'm trying to setup and connect to my remote development SQL Server (SQL 2017) in appsettings.json within .NET Core 3.1, I have tried the following approaches yet without any success.
"ConnectionStrings": {
//"DefaultConnection1": "DATA SOURCE=[servername];UID=[username];PWD=[password];DATABASE=[databasename]",
//"DefaultConnection2": "Data Source=[servername]; Initial Catalog=[databasename];User ID=[username];Password=[password]",
//"DefaultConnection3": "DataSource=[servername];Initial Catalog=[databasename];User Id=[username];password=[password]",
"DefaultConnection4": "Server=[servername];Database=[databasename];User Id=[username];password=[password];Trusted_Connection=False;MultipleActiveResultSets=true;"
},
Error of DefaultConnection1:
ArgumentException: Keyword not supported: 'uid'.
Microsoft.Data.Sqlite.SqliteConnectionStringBuilder.GetIndex(string
keyword))
Error of DefaultConnection2:
ArgumentException: Keyword not supported: 'initial catalog'.
Microsoft.Data.Sqlite.SqliteConnectionStringBuilder.GetIndex(string
keyword)
Error of DefaultConnection3:
ArgumentException: Keyword not supported: 'initial catalog'.
Microsoft.Data.Sqlite.SqliteConnectionStringBuilder.GetIndex(string
keyword)
Error of DefaultConnection4:
ArgumentException: Keyword not supported: 'server'.
Microsoft.Data.Sqlite.SqliteConnectionStringBuilder.GetIndex(string
keyword)
Any ideas, pointers or help is much appreciated.
thanks for your help and advice, i might have just found the solution and am able to connection the SQL database successfully now, the problem was as following:
The following package was installed on the solution:
Microsoft.Data.Sqlite.SqliteConnectionStringBuilder
in Startup.cs the following line was used in the ConfigureServices(IServiceCollection services):
services.AddDbContext<ApplicationDbContext>(options => options.UseSqlLite(Configuration.GetConnectionString("DefaultConnection")));
However after research i found out that i should rather use the following line:
services.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
Which was not accessible due the following package missing:
Microsoft.EntityFrameworkCore.SqlServer
After installing this package via package Manager using the following command:
Install-Package Microsoft.EntityFrameworkCore.SqlServer
I was able to access the SQL server using the following connection string:
"ConnectionStrings": {
"DefaultConnection": "Server=[servername];Database=[databasename];Persist Security Info=True;User ID=[username];Password=[password];MultipleActiveResultSets=True;"
},
For safety, as Christian pointed out, I removed also the other connectionstring references.
Probably it's just because you're not supposed to put comments (//) in JSON as JSON is a data format and doesn't support comments. So try actually removing the lines starting with // from your config.
Your setup in appsettings.json is fine.
Suppose the model in your cs file is mytestModel.
Here is the code to read the connection string:
public class mytestModel : PageModel
{
public string connectstring = "";
private IConfiguration MyConfiguration;
public mytestModel (IConfiguration _configuration)
{
MyConfiguration = _configuration;
}
public void OnGet()
{
connectstring = this.MyConfiguration.GetConnectionString("DefaultConnection4");
}
}
It should be noted that the type of model (eg. PageModel) does not matter. The name of the model is what matters.

Ruby YAML array

I'm using the following resource from elasticsearch:
elasticsearch_configure 'elasticsearch' do
configuration ({
'path.repo' => ["/backups/s3_currently_dev", "/backups/s3_currently", "/backups/s3_daily", "/backups/s3_weekly", "/backups/s3_monthly"]
})
end
I need exactly the following output:
path.repo: ["/backups/s3_currently_dev", "/backups/s3_currently", "/backups/s3_daily", "/backups/s3_weekly", "/backups/s3_monthly"]
But I obtain the following one:
path.repo:
- "/backups/s3_currently_dev"
- "/backups/s3_currently"
- "/backups/s3_daily"
- "/backups/s3_weekly"
- "/backups/s3_monthly"
This doesn't seem to work. How I can obtain the desired output?
Reproduce:
1- Install Chef.
2- Create a cookbook.
3- Use elasticsearch community cookbook to install elasticsearch and configure with the resource shown.
4- Use kitchen or vagrant to create.
You can parse the existing output using YAML.load like so:
require 'yaml'
=> true
config = 'path.repo:
- "/backups/s3_currently_dev"
- "/backups/s3_currently"
- "/backups/s3_daily"
- "/backups/s3_weekly"
- "/backups/s3_monthly"'
=> "path.repo:\n- \"/backups/s3_currently_dev\"\n- \"/backups/s3_currently\"\n- \"/backups/s3_daily\"\n- \"/backups/s3_weekly\"\n- \"/backups/s3_monthly\""
doc = YAML.load config
=> {"path.repo"=>["/backups/s3_currently_dev", "/backups/s3_currently", "/backups/s3_daily", "/backups/s3_weekly", "/backups/s3_monthly"]}
doc["path.repo"]
=> ["/backups/s3_currently_dev", "/backups/s3_currently", "/backups/s3_daily", "/backups/s3_weekly", "/backups/s3_monthly"]

QrCode class not found or interface not found using Endroid/QrCode in Cakephp2.X

I'm new in cakePHP and I'm trying to run Endroid/QrCode in Cakephp2.x with no success. My controller looks like follows:
public function presta_my_function(){
App::import('Vendor', 'Endroid\QrCode', array('file' => 'Endroid/QrCode/QrCode.php'));
in this case I get the following error:
2017-09-27 02:11:55 Error: Fatal Error (1): Interface 'Endroid\QrCode\QrCodeInterface' not found in [C:\MAMP\htdocs\xxxx\app\Vendor\Endroid\QrCode\QrCode.php, line 18].
On the other hand, if try to do an import of QrCodeInterface.php before loading QrCode.php I get the following error:
2017-09-27 02:42:15 Error: Fatal Error (1): Class 'QrCode' not found in [C:\MAMP\htdocs\xxx\app\Controller\ActivitesController.php, line 971].
In this case the code looks like follows:
public function presta_my_space(){
App::import('Vendor', 'Endroid', array('file' => 'Endroid/QrCode/QrCodeInterface.php'));
App::import('Vendor', 'Endroid\QrCode', array('file' => 'Endroid/QrCode/QrCode.php'));
Endroid\QrCode is installed in /app/vendor/Endroid/QrCode.
Any idea about what is failing?
Thank you very much in advance.
You cannot include namespaced, composer based libraries like endroid/QrCode using App::import(), as this will only load a single file. Sure, you could load each and every single file manually, but that's anything but a good idea.
Switch your CakePHP application to using composer (back up your application before fiddling with this), and then ditch App::import() and use the library as shown in their docs.
See Cookbook > Installation > Advanced Installation

Extracting Salesforce data using Camel throws org.apache.camel.NoTypeConversionAvailableException

I am new to Apache Camel and working on a simple java program that can extract Salesforce custom object data using Apache Camel. While running the program it throws org.apache.camel.NoTypeConversionAvailableException. Objects QueryRecordsLine_Item__c and Line_Item__c implements Serializable interface. Kindly help me to fix this.
Code snippet:
from("direct:query")
.to("salesforce:query?sObjectQuery=SELECT name, Unit_Price__c, Units_sold__c, Merchandise__c, Invoice_Statement__c from Line_Item__c&sObjectClass=" + QueryRecordsLine_Item__c.class.getName())
.to("file:E:\\ajagan\\datafiles\\out");
Exception:
Caused by: org.apache.camel.NoTypeConversionAvailableException: No type converter available to convert from type: org.apache.camel.component.salesforce.dto.generated.QueryRecordsLine_Item__c to the required type: java.io.InputStream with value {"done":true,"totalSize":280,"records":[.....]}
at org.apache.camel.impl.converter.BaseTypeConverterRegistry.mandatoryConvertTo(BaseTypeConverterRegistry.java:181)
at org.apache.camel.impl.MessageSupport.getMandatoryBody(MessageSupport.java:99)
... 31 more
You should add camel-jaxb to the classpath, so Camel can covert the salesforce DTO objects (they are JAXB annottated) to XML representation in a stream, that the file endpoint can use.
How about you try converting to a string first:
from("direct:query")
.to(...)
.convertBodyTo(String.class)
.to(...)

Resources