Altering standard MSSqlServerSink table from appsettings - serilog

In my ASP.NET Core 2.1 web API, I use Serilog with MSSqlServerSink. How can I alter the default table structure and add data to those columns by configuring it using appsettings?
I've tried settings the values as per the documentation examples but there are no errors. It is just as if the settings are ignored. I know the settings are being read because some of them are being picked up such as the table name. I've posted questions on other ASP.NET forums and the suggestions don't have any effect. I posted questions on the Serilog Gitter feed but I didn't get an answer. I did post on the github issues and someone suggested upgrading from the latest version to the dev version but this is a live environment. This is the section in the appsettings.json file that configures serilog.
"Serilog": {
"Using": [ "Serilog.Sinks.MSSqlServer" ],
"MinimumLevel": {
"Default": "Information",
"Override": {
"Microsoft": "Warning"
}
},
"WriteTo": [
{
"Name": "MSSqlServer",
"Args": {
"connectionString": "Server=(local);Database=ACLWebAPILogs;trusted_connection=true",
"tableName": "ACLWebAPILog",
"restrictedToMinimumLevel": "Information",
"autoCreateSqlTable": true
"columnOptionsSection": {
"disableTriggers": true,
"removeStandardColumns": [ "MessageTemplate", "Properties" ],
"additionalColumns": [
{
"ColumnName": "ControllerName",
"DataType": "nvarchar",
"AllowNull": true,
"DataLength": 50
},
{
"ColumnName": "MessageType",
"DataType": "nvarchar",
"AllowNull": true,
"DataLength": 50
}
]
}
}
}
]
}
The code that is in the Startup constructor in Startup.cs has the following line to add the logging system:
// Init Serilog configuration
Log.Logger = new LoggerConfiguration()
.ReadFrom.ConfigurationSection(configuration.GetSection("Serilog"))
.CreateLogger();
In the Configure function I do have:
loggerFactory.AddSerilog();
I would have expected this to have removed the MessageTemplate and Properties columns and added the two referenced below. It's as if everything passed autoCreateSqlTable is ignored. I've looked at Enrichers and they don't do what I want.

Update Serilog.Sinks.MSSqlServer to version 5.1.3
Install-Package Serilog.Sinks.MSSqlServer -Version 5.1.3
Check this answer for more details https://stackoverflow.com/a/55264488/3134112

Related

How do you configure Destructurama.Attributes .Destructure.UsingAttribues() in JSON from appsettings?

We use appsettings to configure Serilog via JSON, a fairly standard enterprise practice.
But I'm having trouble enabling the UsingAttributes. How does one enable .Destructure.UsingAttributes via JSON config?
I started with a pure Serliog approach, but they indicate that Serilog.Extras.Attributed is deprecated in favor of using Destructurama.Attributed. And in looking at the Destructurama.Attributed github example, I don't understand how to convert that into a JSON configuration. Their example:
var log = new LoggerConfiguration().Destructure.UsingAttributes()
The Serilog documentation for the "Destructure" option is straightforward:
"Destructure": [
{
"Name": "With",
"Args": { "policy": "Sample.CustomPolicy, Sample" }
},
],
However, I don't know what I would use for the "Sample.CustomPolicy, Sample" to get Destructurama to be enabled.
"Destructure": [
{
"Name": "With",
"Args": { "UsingAttributes": WHAT_GOES_HERE}
},
],
I feel like I'm missing something obvious.
I just encountered the same problem and after a few experiments I figured how to have it working using Destructurama.Attributed version 2.0.0 :
You must specify the following using in JSON configuration to make Serilog able to see the library :
"Serilog":
{
"Using":
[
"Destructurama.Attributed"
],
....
}
Inside Serilog configuration, you have to specify this to Destructure to enable the attributes :
"Destructure":
[
{
"Name": "UsingAttributes"
},
....
]

SAPUI5, Datasource from 2 different URL

I am new in SAPUI5, currently I am building a SAPUI5 application and consumes ODATA services from backend. When I am creating an application and select service URL.
Service URL as following attachment.
However, now in my application I have to add another data source with totally url. In my manifest.json. I just can change different navigation of the same url as following
"dataSources": {
"mainService": {
"uri": "/sap/opu/odata/sap/SEPMRA_SHOP/",
"type": "OData",
"settings": {
"odataVersion": "2.0",
"localUri": "localService/metadata.xml"
}
},
"mainService2": {
"uri": "/odata/V2/OData/OData.svc/",
"type": "OData",
"settings": {
"odataVersion": "2.0",
"localUri": "localService/metadata.xml"
}
}
},
How can I add different url of datasource for SAPUI5 application?
You need to create a Destination in your SAP Cloud Platform cockpit.
You are already using one called "odata - odata" as per your screenshot.
You have the documentation here
And a screenshot below.
Fuertheremore, if you want to access a NW system in your private network from the cloud, you need to set up a Cloud connector. Check the documentation here
SAP Cloud Platform configuration
Once you have your destinations configured and you dataSource block already there (as you have in the screenshot), you need to create 2 OData models. So in your metadata.json file, go to the bottom, and there is a node called 'models' where you probably have something like this:
"models": {
"i18n": {
"type": "sap.ui.model.resource.ResourceModel",
"settings": {
...
}
},
"": {
"type": "sap.ui.model.odata.v2.ODataModel",
"settings": {
"defaultOperationMode": "Server",
"defaultBindingMode": "OneWay",
"defaultCountMode": "Request"
},
"dataSource": "mainService",
"preload": true
},
"dataModel2": {
"type": "sap.ui.model.odata.v2.ODataModel",
"settings": {
"defaultOperationMode": "Server",
"defaultBindingMode": "OneWay",
"defaultCountMode": "Request"
},
"dataSource": "mainService2",
"preload": true
}
}
You need to add the block "dataModel2":{ ... }
Where:
"dataModel2" is the name of your second model (choose the one you like, it doesn't need to be dataModel2).
Make sure that "dataSource": "mainService2" so this model points to your second data source
In the settings you can set the model as you want. Probably the most important is the "defaultBindingMode". Set it as "OneWay" if it is only readable, or "TwoWay" if it is read/write-able.
Then you just need to define all your bindings to this model with the modelName you choose as described in the first bullet point. For instance:
<Text text="{dataModel2>/path/to/my/property"}"></Text>
But be careful with this architecture, as per SAP Best Practices, you should try always to use only one OData service. Having more than one could be a nightmare to maintain, specially if you suscribe to model change/dataRequested/dataReceived events or for error handling with metadataFailed/metadataLoaded events, because you will have to manage them for both models and they are asynchronous...

Serilog cannot show output logs aspnetcore 2.1 vs 2017

I am writing a few webapis using aspnetcore core 2.1
I would like to use serilog and I cannot find a simple example out there that works that gives me a starting point and shows me what I need to do.
I would like to do the following
Setup Serilog in appsetting.json file
Write to VisualStudio output windows
Write to File location eg "C:\Logs"
Inject logger in various controllers
Can somebody either correct my code or point me to a link where it shows how it is used
I have done as follows: (Copy and paste from internet)but they do not show in vs output windows
Not sure if need all of these nugets
Serilog
Serilog.Extensions.Logging
Serilog.Settings.Configuration
Serilog.Sinks.ColoredConsole
Serilog.Sinks.File
Serilog.Sinks.RollingFile
serilog.Sinks.Trace
Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(Configuration)
.Enrich.FromLogContext()
.WriteTo.ColoredConsole()
.WriteTo.Console()
.CreateLogger();
Log.Verbose("This is a verbose statement");
Log.Debug("This is a debug statement");
Log.Information("This is a info statement");
Log.Warning("This is a warning statement");
Log.Error(new IndexOutOfRangeException(), "This is an error statement");
Log.Fatal(new AggregateException(), "This is an fatal statement");
Appsetting file set up serilog
{
"Serilog": {
"MinimumLevel": {
"Default": "Information",
"Override": {
"Microsoft": "Warning",
"System": "Warning"
}
},
"WriteTo": [
{
"Name": "[ColoredConsole]",
"Args": {"outputTemplate": "[{Timestamp:HH:mm:ss.fff}] {Level:u3} - {Message}{NewLine}{Exception}"}
},
"WriteTo": [
{
"Name": "console",
"Args": {"outputTemplate": "[{Timestamp:HH:mm:ss.fff}] {Level:u3} - {Message}{NewLine}{Exception}"}
},
{
"Name": "RollingFile",
"Args": {
"pathFormat": "logs\\log-{Date}.log",
"outputTemplate": "[{Timestamp:dd/MM/yy HH:mm:ss.fff z}] {Level:u3} {Message}{NewLine}{Exception}"
}
}
]
},
Nothing shows in VS OUTPUT WINDOWS
no file is written
Where Am I going wrong?
thanks
You can always start by copying the sample application found here. It will get you a part of your way, and then what you will have to do is add the specific sinks you required.

How to see or debug chrome content script in firefox nightly (webextensions)

Trying to port a working chrome extension to Firefox Nightly 46.0a1 and have a simple question! How do I get the content script to execute or see it at all?
Everything else but the content script seam to be running OK as the background script execute and the popup box is visible. I am able to debug these part of the code.
But the content script do not seam to run in any way!
As far as I understand it is supposed to be part of the normal page javascript environment and visible in the debugger - but it is not. Unable to see any error messages anywhere etc.
Might have used some unsupported API by mistake, but still strange that I get no warnings and are unable to see anything.
Any proposal about how to proceed?
Manifest file below:
{
"name": "Bla Bla",
"version": "0.0.1",
"manifest_version": 2,
"description": "A description",
"homepage_url": "https://aaa.org",
"icons":
{
"16": "icons/lock_red16.png",
"48": "icons/lock_red48.png",
"128": "icons/lock_red128.png"
},
"default_locale": "en",
"background":
{
"scripts":
[
"js/lib/jserror/jserror.js",
"js/lib/lang/languagedb.js",
"js/lib/lz77.js",
"js/lib/pcrypt.js",
"js/lib/pcryptapi.js",
"js/lib/forge.bundle.js",
"js/lib/elliptic.js",
"js/lib/srp6a/biginteger.js",
"js/lib/srp6a/isaac.js",
"js/lib/srp6a/random.js",
"js/lib/srp6a/sha256.js",
"js/lib/srp6a/thinbus-srp6client.js",
"js/lib/srp6a/thinbus-srp-config.js",
"js/lib/srp6a/thinbus-srp6a-config-sha256.js",
"js/pcrypt_shared.js",
"js/pcrypt_extension.js",
"src/bg/background.js"
],
"persistent": true
},
"browser_action":
{
"default_icon":
{
"16": "icons/lock_red16.png",
"48": "icons/lock_red48.png",
"128": "icons/lock_red128.png"
},
"default_title": "Password Crypt",
"default_popup": "src/browser_action/popup.html"
},
"permissions":
[
"clipboardWrite",
"storage"
],
"content_scripts":
[
{
"matches":
[
"http://*/*",
"https://*/*"
],
"js":
[
"js/pcrypt_extension.js",
"src/inject/inject.js"
]
}
],
"externally_connectable":
{
"matches":
[
"https://*.aaa.dk/*",
"https://*.aaa.org/*"
]
},
"web_accessible_resources":
[
"icons/*.png"
],
"applications":
{
"gecko":
{
"id": "benny#aaa.dk",
"strict_min_version": "40.0.0",
"strict_max_version": "50.*",
"update_url": "https://aaa.org/addon"
}
}
}
As far as I understand it is supposed to be part of the normal page javascript environment and visible in the debugger - but it is not.
No, they're not. They run in slightly more privileged contexts separate from the page environment so they can access the webextension APIs.
If you have e10s off you can use the browser toolbox. If it is on you need to use the browser content toolbox instead. You can also try about:debugging, although i'm not sure whether that already works for webextensions.
MDN docs have everything you need to know about debugging WebExt, including content scripts.

Visual Studio error when trying to create MVC application on Azure

I want to create a new MVC application with Visual Studio Community 2015. I've followed this tutorial on how to do this and I've gone as far as creating the application, but after I click 'Create' to create the application, the error message below is displayed.
Is this message referring to the Azure API version for Visual Studio? If so, how should I resolve this? I've looked online and I can't seem to find anything about this error. I'm a newbie at this, so I'm not sure if I've overlooked anything, but I don't seem to according to the tutorial. Any help is greatly appreciated!
UPDATE
The image below shows the SQL API version I've found. It's odd thought, because it does not match the version shown in the error message.
As the error message says the API have to be in correct format yyyy-MM-dd.
API version I was using recently was 2014-04-01 or 2014-04-01-preview. Try any of these when defining SqlServer resouce.
Also have a look at resources.azure.com if you have any SqlServers created and double check the API version from there..
This does not relate to the Azure Sdk version for Visual Studio. It relates to the (in your case) API version used to create SqlServer instance using Azure Resource Manager
Sample SqlServer and database resource node:
"resources": [
{
"name": "[parameters('sqlServerName')]",
"type": "Microsoft.Sql/servers",
"location": "[resourceGroup().location]",
"apiVersion": "2014-04-01-preview",
"dependsOn": [ ],
"tags": {
"displayName": "SqlServer"
},
"properties": {
"administratorLogin": "[parameters('sqlDatabaseUserName')]",
"administratorLoginPassword": "[parameters('sqlDatabasePassword')]",
"version": "12.0"
},
"resources": [
{
"name": "AllowAllWindowsAzureIps",
"type": "firewallrules",
"location": "[resourceGroup().location]",
"apiVersion": "2014-04-01-preview",
"dependsOn": [
"[concat('Microsoft.Sql/servers/', parameters('sqlServerName'))]"
],
"properties": {
"startIpAddress": "0.0.0.0",
"endIpAddress": "255.255.255.255"
}
},
{
"name": "[parameters('databaseName')]",
"type": "databases",
"location": "[resourceGroup().location]",
"apiVersion": "2014-04-01-preview",
"kind": "v12.0",
"dependsOn": [
"[parameters('sqlServerName')]"
],
"tags": {
"displayName": "SqlDatabase"
},
"properties": {
"collation": "[parameters('sqlDatabaseUriNameCollation')]",
"edition": "[parameters('sqlDatabaseUriNameEdition')]",
"maxSizeBytes": "10737418240"
//10 gigs currently
}
}
]
}
Also as #Robert McKee pointed make sure you have latest Azure SDK (2.7.1 or 2.8 released recently)
I'm not sure how, but this evening when I went to try it again, it worked. Thank you all for your answers!

Resources