NLog use Connection String Name in appsettings - asp.net

I have an NLog database target that looks like this:
<target xsi:type="Database" name="database"
connectionString="Server=.\SQLEXPRESS;Database=ApplicationOne;Trusted_Connection=True;MultipleActiveResultSets=true;User Id=User0101;Password=PW0101"
commandText="INSERT INTO [SchemaOne].[EventLogs](Id, Message, Level, Logger )VALUES(NewID(), #Message, #Level, #Logger)">
<parameter name="#Message" layout="${message}" />
<parameter name="#Level" layout="${level}" />
<parameter name="#Logger" layout="${logger}" />
</target>
Is it possible to change the connectionString to use connectionStringName from my appsettings instead?
My appsettings is called dssettings.json and it contains the connection details here:
"DatabaseConfiguration": {
"DatabaseName": "ApplicationOne",
"ConnectionName": "DefaultConnection",
"ConnectionString": "Server=.\\SQLEXPRESS;Database=ApplicationOne;Trusted_Connection=True;MultipleActiveResultSets=true;User Id=User0101;Password=PW0101"
},

Update NLog.Extension.Logging ver. 1.4.0
With NLog.Extension.Logging ver. 1.4.0 then you can now use ${configsetting}
See also: https://github.com/NLog/NLog/wiki/ConfigSetting-Layout-Renderer
Original Answer
With help from nuget-package NLog.Appsettings.Standard then you can normally do this:
<extensions>
<add assembly="NLog.Appsettings.Standard" />
</extensions>
<targets>
<target xsi:type="Database" name="database"
connectionString="${appsettings:name=DatabaseConfiguration.ConnectionString}"
commandText="INSERT INTO [SchemaOne].[EventLogs](Id, Message, Level, Logger )VALUES(NewID(), #Message, #Level, #Logger)">
<parameter name="#Message" layout="${message}" />
<parameter name="#Level" layout="${level}" />
<parameter name="#Logger" layout="${logger}" />
</target>
</targets>
But because you are using a special dssettings.json (instead of appsettings.json), then you probably have to implement your own custom NLog layout renderer:
https://github.com/NLog/NLog/wiki/How-to-write-a-custom-layout-renderer
Maybe you can use the source-code from the above nuget-package as inspiration for loading dssettings.json. Or maybe create PullRequest that adds support for specifying non-default config-filename.

Related

Unable to create third index in elastic search for logging using NLog in Asp.net core

Hello Everyone,
I am new to the elk stack and trying to do logging using elastic search. I want to create different index for different different services in api. I am able to create two indexes of different services but can not do the same for third index.
Following is my nconfig file
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
autoReload="true"
throwExceptions="false"
internalLogLevel="Trace" internalLogFile="c:\temp1\nlog-internal.log">
<!-- optional, add some variables
https://github.com/nlog/NLog/wiki/Configuration-file#variables
-->
<variable name="myvar" value="myvalue"/>
<extensions>
<add assembly="NLog.Targets.ElasticSearch"/>
<add assembly="NLog.Web.AspNetCore"/>
</extensions>
<!--
See https://github.com/nlog/nlog/wiki/Configuration-file
for information on customizing logging rules and outputs.
-->
<targets>
<!--
add your targets here
See https://github.com/nlog/NLog/wiki/Targets for possible targets.
See https://github.com/nlog/NLog/wiki/Layout-Renderers for the possible layout renderers.
-->
<target xsi:type="File" name="f" fileName="${basedir}/logs/log.txt"
archiveFileName="${basedir}/logs/archives/log.txt"
archiveAboveSize="5242880"
archiveEvery="Day"
archiveNumbering = "Rolling"
maxArchiveFiles="3"
layout="${longdate} ${uppercase:${level}} ${message}" />
<target xsi:type="BufferingWrapper" name="ElasticSearch"
flushTimeout="5000">
<target xsi:type="ElasticSearch" name="elastic" index="aquaparallelapi"
uri="http://localhost:9200"
layout ="API:aquaparallelapi|${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}|url: ${aspnet-request-url}|action: ${aspnet-mvc-action}" />
</target>
<target xsi:type="BufferingWrapper" name="ElasticSearch"
flushTimeout="5000">
<target xsi:type="ElasticSearch" name="elastic1" index="aquaparallelapiprogress"
uri="http://localhost:9200"
layout ="API:aquaparallelapi|${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}|url: ${aspnet-request-url}|action: ${aspnet-mvc-action}" />
</target>
<target xsi:type="BufferingWrapper" name="ElasticSearch"
flushTimeout="5000">
<target xsi:type="ElasticSearch" name="elastic2" index="aquaparallelapitestcase"
uri="http://localhost:9200"
layout ="API:aquaparallelapi|${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}|url: ${aspnet-request-url}|action: ${aspnet-mvc-action}" />
</target>
<!--
Write events to a file with the date in the filename.
<target xsi:type="File" name="f" fileName="${basedir}/logs/${shortdate}.log"
layout="${longdate} ${uppercase:${level}} ${message}" />
-->
</targets>
<rules>
<!-- add your logging rules here -->
<logger enabled="true" name="*" minlevel="Debug" writeTo="f" />
<logger enabled="true" name="*" minlevel="Debug" writeTo="elastic" />
<logger enabled="true" name="AquaParallelAPI.Controllers.ProgressController" minlevel="Debug" writeTo="elastic1" />
<logger enabled="true" name="AquaParallelAPI.Controllers.TestCaseController" minlevel="Debug" writeTo="elastic2" />
</rules>
</nlog>
As you can see above indexes aquaparallelapi and aquaparallelapiprogress is created and gives the desired result but index aquaparallelapitestcase is not created. When I tried to do
http://localhost:9200/aquaparallelapitestcase
then
{"error":{"root_cause":[{"type":"index_not_found_exception","reason":"no such index [aquaparallelapitestcase]","resource.type":"index_or_alias","resource.id":"aquaparallelapitestcase","index_uuid":"_na_","index":"aquaparallelapitestcase"}],"type":"index_not_found_exception","reason":"no such index [aquaparallelapitestcase]","resource.type":"index_or_alias","resource.id":"aquaparallelapitestcase","index_uuid":"_na_","index":"aquaparallelapitestcase"},"status":404}
Please let me know where I am wrong?

NLog "Input string was not in a correct format." using windows-identity

I am trying to log some information to database, but being kind of new to nlog config ( until now the default config from Tutorials worked fine) I am not sure what I am missing from my config to work.
I get this error when I app starts
2022-02-24 17:06:46.1375 Error Failed loading from config file location: C:\Repos\App\bin\Debug\netcoreapp3.1\NLog.config Exception: NLog.NLogConfigurationException: Exception when parsing C:\Repos\App\bin\Debug\netcoreapp3.1\NLog.config.
---> System.FormatException: Input string was not in a correct format.
at System.Text.StringBuilder.FormatError()
at System.Text.StringBuilder.AppendFormatHelper(IFormatProvider provider, String format, ParamsArray args)
at System.String.FormatHelper(IFormatProvider provider, String format, ParamsArray args)
at System.String.Format(String format, Object[] args)
at NLog.NLogConfigurationException..ctor(Exception innerException, String message, Object[] messageParameters)
at NLog.Config.LoggingConfigurationParser.ConfigureObjectFromAttributes(Object targetObject, ILoggingConfigurationElement element, Boolean ignoreType)
at NLog.Config.LoggingConfigurationParser.ParseTargetElement(Target target, ILoggingConfigurationElement targetElement, Dictionary`2 typeNameToDefaultTargetParameters)
at NLog.Config.LoggingConfigurationParser.ParseTargetsElement(ILoggingConfigurationElement targetsElement)
at NLog.Config.LoggingConfigurationParser.ParseNLogSection(ILoggingConfigurationElement configSection)
at NLog.Config.XmlLoggingConfiguration.ParseNLogSection(ILoggingConfigurationElement configSection)
at NLog.Config.LoggingConfigurationParser.LoadConfig(ILoggingConfigurationElement nlogConfig, String basePath)
at NLog.Config.XmlLoggingConfiguration.ParseNLogElement(ILoggingConfigurationElement nlogElement, String filePath, Boolean autoReloadDefault)
at NLog.Config.XmlLoggingConfiguration.ParseTopLevel(NLogXmlElement content, String filePath, Boolean autoReloadDefault)
at NLog.Config.XmlLoggingConfiguration.Initialize(XmlReader reader, String fileName, Boolean ignoreErrors)
--- End of inner exception stack trace ---
at NLog.Config.XmlLoggingConfiguration.Initialize(XmlReader reader, String fileName, Boolean ignoreErrors)
at NLog.Config.XmlLoggingConfiguration..ctor(XmlReader reader, String fileName, LogFactory logFactory)
at NLog.Config.LoggingConfigurationFileLoader.LoadXmlLoggingConfiguration(XmlReader xmlReader, String configFile, LogFactory logFactory)
at NLog.Config.LoggingConfigurationFileLoader.LoadXmlLoggingConfigurationFile(LogFactory logFactory, String configFile)
at NLog.Config.LoggingConfigurationFileLoader.TryLoadLoggingConfiguration(LogFactory logFactory, String configFile, LoggingConfiguration& config)
My Config files looks like this
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true"
throwConfigExceptions="true"
internalLogLevel="trace"
internalLogFile="c:\temp\internal-nlog-AspNetCore3.txt">
<!-- enable asp.net core layout renderers -->
<extensions>
<add assembly="NLog.Web.AspNetCore"/>
</extensions>
<!-- the targets to write to -->
<targets>
<!-- File Target for all log messages with basic details -->
<target xsi:type="File" name="allfile" fileName="c:\temp\nlog-AspNetCore3-all-${shortdate}.log"
layout="${longdate}|${event-properties:item=EventId_Id:whenEmpty=0}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}" />
<!-- File Target for own log messages with extra web details using some ASP.NET core renderers -->
<target xsi:type="File" name="ownFile-web" fileName="c:\temp\nlog-AspNetCore3-own-${shortdate}.log"
layout="${longdate}|${event-properties:item=EventId_Id:whenEmpty=0}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}|url: ${aspnet-request-url}|action: ${aspnet-mvc-action}|" />
<!--Console Target for hosting lifetime messages to improve Docker / Visual Studio startup detection -->
<target xsi:type="Console" name="lifetimeConsole" layout="${MicrosoftConsoleLayout}" />
<target xsi:type="database" name="database"
layout="${longdate}|${level:uppercase=true}|${logger}|${message}|identity:${identity}|windows-identity:${windows-identity}">
<connectionString>
Data Source=MYCOMPUTER;Initial Catalog=DatabaseName;Integrated Security=True
</connectionString>
<commandText>
INSERT INTO SystemLogging(LogDate,LogLevel,LogLogger,LogMessage,LogMachineName, LogUserName, LogCallSite, LogThread, LogException, LogStackTrace)
VALUES(#time_stamp, #level, #logger, #message,#machinename, #user_name, #call_site, #threadid, #log_exception, #stacktrace);
</commandText>
<parameter name="#time_stamp" layout="${longdate}"/>
<parameter name="#level" layout="${level}"/>
<parameter name="#logger" layout="${logger}"/>
<parameter name="#message" layout="${message}"/>
<parameter name="#machinename" layout="${machinename}"/>
<parameter name="#user_name" layout="${windows-identity:domain=true}"/>
<parameter name="#call_site" layout="${callsite:filename=true}"/>
<parameter name="#threadid" layout="${threadid}"/>
<parameter name="#log_exception" layout="${exception}"/>
<parameter name="#stacktrace" layout="${stacktrace}"/>
</target>
</targets>
<!-- rules to map from logger name to target -->
<rules>
<!--All logs, including from Microsoft-->
<logger name="*" minlevel="Trace" writeTo="allfile" />
<!--Output hosting lifetime messages to console target for faster startup detection -->
<logger name="Microsoft.Hosting.Lifetime" minlevel="Info" writeTo="lifetimeConsole, ownFile-web" final="true" />
<!--Skip non-critical Microsoft logs and so log only own logs-->
<logger name="Microsoft.*" maxlevel="Info" final="true" />
<!-- BlackHole -->
<logger name="*" minlevel="Trace" writeTo="ownFile-web" />
</rules>
</nlog>
I know for a fact the problem is somewhere in line 28, layout of db connection.
layout="${longdate}|${level:uppercase=true}|${logger}|${message}|identity:${identity}|windows-identity:${windows-identity}"
If I remove this line however I get an other error
"LayoutRenderer cannot be found: 'windows-identity'"
It feels like an obvious problem, however search the internet I could not find a solution. Anyone with more experience in NLog, can you share an example of DB Logging that uses Windows-Auth for db logging and not a username/password in connection string.
I've also tried ( added '' to windows-identity, but that didn't work either )
layout="${longdate}|${level:uppercase=true}|${logger}|${message}|identity: '${identity}' | windows-identity: '${windows-identity}'"
Edit:
Updated config
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true"
throwConfigExceptions="true"
internalLogLevel="trace"
internalLogFile="c:\temp\internal-nlog-AspNetCore3.txt">
<!-- enable asp.net core layout renderers -->
<extensions>
<add assembly="NLog.Web.AspNetCore"/>
<add assembly="NLog.WindowsIdentity"/>
</extensions>
<!-- the targets to write to -->
<targets>
<!-- File Target for all log messages with basic details -->
<target xsi:type="File" name="allfile" fileName="c:\temp\nlog-AspNetCore3-all-${shortdate}.log"
layout="${longdate}|${event-properties:item=EventId_Id:whenEmpty=0}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}" />
<!-- File Target for own log messages with extra web details using some ASP.NET core renderers -->
<target xsi:type="File" name="ownFile-web" fileName="c:\temp\nlog-AspNetCore3-own-${shortdate}.log"
layout="${longdate}|${event-properties:item=EventId_Id:whenEmpty=0}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}|url: ${aspnet-request-url}|action: ${aspnet-mvc-action}|" />
<!--Console Target for hosting lifetime messages to improve Docker / Visual Studio startup detection -->
<target xsi:type="Console" name="lifetimeConsole" layout="${MicrosoftConsoleLayout}" />
<target xsi:type="database" name="database"
layout="${longdate}|${level:uppercase=true}|${logger}|${message}|identity:${identity}|windows-identity:${environment-user}">
<connectionString>
Data Source=MYCOMPUTER;Initial Catalog=DatabaseName;Integrated Security=True
</connectionString>
<commandText>
INSERT INTO SystemLogging(LogDate,LogLevel,LogLogger,LogMessage,LogMachineName, LogUserName, LogCallSite, LogThread, LogException, LogStackTrace)
VALUES(#time_stamp, #level, #logger, #message,#machinename, #user_name, #call_site, #threadid, #log_exception, #stacktrace);
</commandText>
<parameter name="#time_stamp" layout="${longdate}"/>
<parameter name="#level" layout="${level}"/>
<parameter name="#logger" layout="${logger}"/>
<parameter name="#message" layout="${message}"/>
<parameter name="#machinename" layout="${machinename}"/>
<parameter name="#user_name" layout="${windows-identity:domain=true}"/>
<parameter name="#call_site" layout="${callsite:filename=true}"/>
<parameter name="#threadid" layout="${threadid}"/>
<parameter name="#log_exception" layout="${exception}"/>
<parameter name="#stacktrace" layout="${stacktrace}"/>
</target>
</targets>
<!-- rules to map from logger name to target -->
<rules>
<!--All logs, including from Microsoft-->
<logger name="*" minlevel="Trace" writeTo="allfile" />
<!--Output hosting lifetime messages to console target for faster startup detection -->
<logger name="Microsoft.Hosting.Lifetime" minlevel="Info" writeTo="lifetimeConsole, ownFile-web" final="true" />
<!--Skip non-critical Microsoft logs and so log only own logs-->
<logger name="Microsoft.*" maxlevel="Info" final="true" />
<!-- BlackHole -->
<logger name="*" minlevel="Trace" writeTo="ownFile-web" />
</rules>
</nlog>
So it turns out the layout is not working. I removed it and app would start with no erros. However I still had to add a rule in order to make logs in db. Here is the working version of the nlog file.
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true"
throwConfigExceptions="true"
internalLogLevel="trace"
internalLogFile="c:\temp\internal-nlog-AspNetCore3.txt">
<!-- enable asp.net core layout renderers -->
<extensions>
<add assembly="NLog.Web.AspNetCore"/>
<add assembly="NLog.WindowsIdentity"/>
</extensions>
<!-- the targets to write to -->
<targets>
<!-- File Target for all log messages with basic details -->
<target xsi:type="File" name="allfile" fileName="c:\temp\nlog-AspNetCore3-all-${shortdate}.log"
layout="${longdate}|${event-properties:item=EventId_Id:whenEmpty=0}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}" />
<!-- File Target for own log messages with extra web details using some ASP.NET core renderers -->
<target xsi:type="File" name="ownFile-web" fileName="c:\temp\nlog-AspNetCore3-own-${shortdate}.log"
layout="${longdate}|${event-properties:item=EventId_Id:whenEmpty=0}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}|url: ${aspnet-request-url}|action: ${aspnet-mvc-action}|" />
<!--Console Target for hosting lifetime messages to improve Docker / Visual Studio startup detection -->
<target xsi:type="Console" name="lifetimeConsole" layout="${MicrosoftConsoleLayout}" />
<target xsi:type="database" name="database">
<connectionString>
Data Source=MYCOMPUTER;Initial Catalog=DbName;Integrated Security=True
</connectionString>
<commandText>
INSERT INTO SystemLogging(LogDate,LogLevel,LogLogger,LogMessage,LogMachineName, LogUserName, LogCallSite, LogThread, LogException, LogStackTrace)
VALUES(#time_stamp, #level, #logger, #message,#machinename, #user_name, #call_site, #threadid, #log_exception, #stacktrace);
</commandText>
<parameter name="#time_stamp" layout="${longdate}"/>
<parameter name="#level" layout="${level}"/>
<parameter name="#logger" layout="${logger}"/>
<parameter name="#message" layout="${message}"/>
<parameter name="#machinename" layout="${machinename}"/>
<parameter name="#user_name" layout="${windows-identity:domain=true}"/>
<parameter name="#call_site" layout="${callsite:filename=true}"/>
<parameter name="#threadid" layout="${threadid}"/>
<parameter name="#log_exception" layout="${exception}"/>
<parameter name="#stacktrace" layout="${stacktrace}"/>
</target>
</targets>
<!-- rules to map from logger name to target -->
<rules>
<!--All logs, including from Microsoft-->
<logger name="*" minlevel="Trace" writeTo="allfile" />
<logger name="*" minLevel="Trace" writeTo="database"/>
<!--Output hosting lifetime messages to console target for faster startup detection -->
<logger name="Microsoft.Hosting.Lifetime" minlevel="Info" writeTo="lifetimeConsole, ownFile-web" final="true" />
<!--Skip non-critical Microsoft logs and so log only own logs-->
<logger name="Microsoft.*" maxlevel="Info" final="true" />
<!-- BlackHole -->
<logger name="*" minlevel="Trace" writeTo="ownFile-web" />
</rules>
</nlog>
The NLog Database-Target doesn't have a Layout-property, that can be assigned. Instead use input parameter-collection.
WindowsIdentity-nuget-package is required for ${windows-identity} on NetCore, and must be included:
<extensions>
<add assembly="NLog.Web.AspNetCore"/>
<add assembly="NLog.WindowsIdentity"/>
</extensions>
Maybe you are looking for ${environment-user} ?
See also: https://github.com/NLog/NLog/wiki/Windows-Identity-Layout-Renderer

How to use xdt-transform when the Web.config element already contains a different xmlns

Using Visual Studio Web.Config Transforms, I want to include the following line in Web.Debug.Config: <add source="*.amazonaws.com" />
This is my Web.config
<configuration>
<!--
-- More config here
-->
<nwebsec>
<httpHeaderSecurityModule xmlns="http://nwebsec.com/HttpHeaderSecurityModuleConfig.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="NWebsecConfig/HttpHeaderSecurityModuleConfig.xsd">
<securityHttpHeaders>
<content-Security-Policy enabled="true">
<default-src none="true" />
<script-src self="true" unsafeEval="true">
<add source="https://cdnjs.cloudflare.com"/>
</script-src>
<style-src unsafeInline="true" self="true">
<add source="https://cdnjs.cloudflare.com"/>
</style-src>
<img-src self="true">
<add source="data:" />
<add source="*.w3.org"/>
<!-- ******** I want to insert new source here for Dev ******** -->
</img-src>
<object-src none="true" />
<media-src none="true" />
<frame-ancestors none="true" />
<report-uri enableBuiltinHandler="true"/>
</content-Security-Policy>
</securityHttpHeaders>
</httpHeaderSecurityModule>
</nwebsec>
</configuration>
I have done what is suggested here, in Web.Debug.config:
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.web></system.web>
<nwebsec>
<httpHeaderSecurityModule> <!-- I have remove xmlns=... from this element -->
<securityHttpHeaders>
<content-Security-Policy enabled="true">
<img-src self="true" xdt:Transform="Remove" />
<img-src self="true" xdt:Transform="InsertIfMissing">
<add source="data:" />
<add source="*.w3.org"/>
<add source="*.amazonaws.com" />
</connect-src>
</content-Security-Policy>
</securityHttpHeaders>
</httpHeaderSecurityModule>
</nwebsec>
</configuration>
But the new line is not added, how can I do this?
I think this is because httpHeaderSecurityModule has xmlns attribute but don't know how to solve this issue?
Note that I have removed the xmlns=... from httpHeaderSecurityModule in the transform file, if I include the namespace I get the following syntax error:
The 'http://schemas.microsoft.com/XML-Document-Transform:Transform'
attribute is not declared
I am not sure if there is a better solution but I could not get the transforms working inside httpHeaderSecurityModule (which has xmlns=...) element, according to MS documentation:
The root element of a transform file must specify the
XML-Document-Transform namespace in its opening tag
The only way that I could do this transform was to replace everything above the element which has xmlns, i.e.
<nwebsec xdt:Transform="Remove" />
<nwebsec xdt:Transform="InsertIfMissing">
<httpHeaderSecurityModule xmlns="http://nwebsec.com/HttpHeaderSecurityModuleConfig.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="NWebsecConfig/HttpHeaderSecurityModuleConfig.xsd">
<securityHttpHeaders>
<content-Security-Policy enabled="true">
<default-src none="true" />
<script-src self="true" unsafeEval="true">
<add source="https://cdnjs.cloudflare.com"/>
</script-src>
<style-src unsafeInline="true" self="true">
<add source="https://cdnjs.cloudflare.com"/>
</style-src>
<img-src self="true">
<add source="data:" />
<add source="*.w3.org"/>
<!-- ******** I want to insert new source here for Dev ******** -->
</img-src>
<object-src none="true" />
<media-src none="true" />
<frame-ancestors none="true" />
<report-uri enableBuiltinHandler="true"/>
</content-Security-Policy>
</securityHttpHeaders>
</httpHeaderSecurityModule>
</nwebsec>
One alternative could be to use a separate config file instead of a full transformation. You can do something like this:
<nwebsec xdt:Transform="Remove" />
<nwebsec xdt:Transform="InsertIfMissing">
<httpHeaderSecurityModule configSource="NWebsec.config" >
</httpHeaderSecurityModule>
</nwebsec>
Unfortunately you cannot directly use the nwebsec elemente (see here why).

MSDeploy not replacing encoded xml strings

In web.config I have:
<applicationSettings>
<App.Properties.Settings>
<setting name="ProfitConnectorToken" serializeAs="String" xdt:Transform="Replace" xdt:Locator="Match(name)">
<value>__ProfitConnectorToken__</value>
</setting>
</App.Properties.Settings>
In my parameters.xml:
<parameter name="ProfitConnectorToken" description="Description for ProfitConnectorToken" defaultvalue="__PROFITCONNECTORTOKEN__" tags="">
<parameterentry kind="XmlFile" scope="\\web.config$" match="/configuration/applicationSettings/App.Properties.Settings/setting[#name='ProfitConnectorToken']/value/text()" />
And in my SetParameters.xml:
<setParameter name="ProfitConnectorToken" value="<token><version>1</version><data>XXXXXXXXXXXXXXXXXXXXXXXXX</data></token>" />
But this value is not set when the web application is deployed. When I change my SetParameters.xml to:
<setParameter name="ProfitConnectorToken" value="TEST" />
It does work, so my XPath is correct. Why is the encoded xml value not set?

"classes" parallel in TestNG test suite doesn't work when executing the suite in TestNG Ant task

I set up Selenium grid2 and it works well with following paralleled TestNG test suite:
<!DOCTYPE suite SYSTEM "http://beust.com/testng/testng-1.0.dtd" >
<suite name="Sample Test Suite" parallel="classes" thread-count="2">
<test name="Test in Chrome" preserve-order="true">
<parameter name="browser" value="chrome" />
<classes>
<class name="testCases.SampleCase1" />
<class name="testCases.SampleCase2" />
</classes>
</test>
</suite>
But the parallel doesn't work any more when I execute the tests in TestNG Ant task.
And it works again after I change the parallel mode in the test suite file with "tests" as below:
<!DOCTYPE suite SYSTEM "http://beust.com/testng/testng-1.0.dtd" >
<suite name="Sample Test Suite" parallel="tests" thread-count="2">
<test name="Test1 in Chrome" preserve-order="true">
<parameter name="browser" value="chrome" />
<classes>
<class name="testCases.SampleCase1" />
</classes>
</test>
<test name="Test2 in Chrome" preserve-order="true">
<parameter name="browser" value="chrome" />
<classes>
<class name="testCases.SampleCase2" />
</classes>
</test>
</suite>
So does that mean TestNG ant task doesn't support "classes" paralleled test suite?
This issue is solved after replace the tsetng.jar from version 6.2 to 6.8.

Resources