NLog outputting all fields in `message` property - redis

I'm using NLog with a Redis target. In an older version all of the attributes in my layout used to appear as 1st class data-items when viewing in Kibana.
Since upgrading to the latest version they all appear as a JSON encoded string value against a single data-item named message.
I've tried specifying a JsonLayout for the message value but it has made no difference
<targets async="true">
<target xsi:type="FallbackGroup" name="fallbacklogger" returnToFirstOnSuccess="true">
<target xsi:type="Redis" name="RedisLog" appName="${appName}" environmentKey="EnvironmentName" connectionStringKey="LoggingRedisConnectionString" includeAllProperties="true" keySettingsKey="LoggingRedisKey">
<layout xsi:type="JsonLayout">
<attribute name="message" encode="false">
<layout type="JsonLayout" includeAllProperties="true" includeMdlc="true"></layout>
</attribute>
</layout>
</target>
</target>
</targets>
How do I get these back to first class data-items in Kibana so that I can click the Filter button against them?

Someone at work fixed this problem, he said he upgraded all dependencies to the latest version and then changed the following:

Related

How can you make two different NLog targets with same date inside?

I have the following two targets defined in NLog.config inside my ASP.NET Core project:
<targets>
<target name="MyApp" xsi:type="File"
fileName="${specialfolder:folder=ApplicationData}/MyApp/${date:format=yyyyMMdd_HHmmss:cached=true}_MyApp.log"
layout="${longdate}|${level:uppercase=true}|${logger}|${message}"
deleteOldFileOnStartup="false"/>
<target name="MyAppAll" xsi:type="File"
fileName="${specialfolder:folder=ApplicationData}/MyApp/${date:format=yyyyMMdd_HHmmss:cached=true}_MyApp.log"
layout="${longdate}|${level:uppercase=true}|${logger}|${message}"
deleteOldFileOnStartup="false"/>
</targets>
MyApp target logs all my logs from the app while MyAppAll includes some framework logs as well.
I am trying to get the NLog to create two log files that have the same timestamp but what I have observed is that MyAppAll will be created immediately on app start since this is the time framework logs start while MyApp will only be created once I send request to API and the result is that I have two files with different dates.
Any ideas on how to solve this?
You can use ${processinfo:StartTime}:
<targets>
<target name="MyApp" xsi:type="File"
fileName="${specialfolder:folder=ApplicationData}/MyApp/${processinfo:StartTime:format=yyyyMMdd_HHmmss:cached=true}_MyApp.log"
layout="${longdate}|${level:uppercase=true}|${logger}|${message}" />
<target name="MyAppAll" xsi:type="File"
fileName="${specialfolder:folder=ApplicationData}/MyApp/${processinfo:StartTime:format=yyyyMMdd_HHmmss:cached=true}_MyApp.log"
layout="${longdate}|${level:uppercase=true}|${logger}|${message}" />
</targets>
See also: https://github.com/NLog/NLog/wiki/ProcessInfo-Layout-Renderer
Notice having 2 file-targets sharing the same filename is not recommended. Forexample with NLog 5 where KeepFileOpen=true by default, then one will stop working.

Msbuild just produces a package but does not deploy it when using a publish profile. Why?

MSBuild really seems to like me.
Recently I am trying out the different possibilities to build and deploy from command line.
However I am experiencing some seemingly strange behaviour when I pass a publish profile to MSBuild.
Here is an example of what I just did:
I deploy to a local IIS for the moment with a command such as this:
msbuild D:\PathToFile\DeployDBVariation01\DeployDBVariation01\DeployDBVariation01.csproj
/p:Configuration=Release;
Platform=AnyCpu;
DeployOnBuild=true;
DeployTarget=MSDeployPublish;
MSDeployServiceURL="localhost";
DeployIisAppPath="DeployApp/DeployThis";
MSDeployPublishMethod=InProc;
Username=thisIsNotActuallyMyUsername;
password=guesswhat;
AllowUntrustedCertificate=true
And this works! After that it is successfully deployed and I can call it in a browser.
However, since Visual Studio gives us the comfort of using publishing profiles I wanted to try that in conjunction with MSBuild over command line and tried the following command:
msbuild D:\PathToFile\DeployDBVariation01\DeployDBVariation01\DeployDBVariation01.csproj
/p:DeployOnBuild=true;
AllowUntrustedCertificate=true;
PublishProfile=ReleaseLocal
ReleaseLocal is a profile I created in Visual Studio and it looks like this:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>MSDeploy</WebPublishMethod>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish />
<ExcludeApp_Data>False</ExcludeApp_Data>
<MSDeployServiceURL>localhost</MSDeployServiceURL>
<DeployIisAppPath>DeployApp/DeployThis</DeployIisAppPath>
<RemoteSitePhysicalPath />
<SkipExtraFilesOnServer>True</SkipExtraFilesOnServer>
<MSDeployPublishMethod>InProc</MSDeployPublishMethod>
<EnableMSDeployBackup>False</EnableMSDeployBackup>
<UserName />
<_SavePWD>False</_SavePWD>
<PublishDatabaseSettings>
<Objects xmlns="">
<ObjectGroup Name="DefaultConnection" Order="1" Enabled="False">
<Destination Path="Data Source=.\SQLEXPRESS;Initial Catalog=HorstDataProductive;User ID=sa;Password=GuessWhat" />
<Object Type="DbDacFx">
<PreSource Path="Data Source=.\SQLEXPRESS;Initial Catalog=HorstData;User ID=sa;Password=GuessWhat" includeData="False" />
<Source Path="$(IntermediateOutputPath)AutoScripts\DefaultConnection_IncrementalSchemaOnly.dacpac" dacpacAction="Deploy" />
</Object>
<UpdateFrom Type="Web.Config">
<Source MatchValue="Data Source=.\SQLEXPRESS;Initial Catalog=HorstData;User ID=sa;Password=GuessWhat" MatchAttributes="$(UpdateFromConnectionStringAttributes)" />
</UpdateFrom>
</ObjectGroup>
</Objects>
</PublishDatabaseSettings>
</PropertyGroup>
<ItemGroup>
<MSDeployParameterValue Include="$(DeployParameterPrefix)DefaultConnection-Web.config Connection String">
<ParameterValue>Data Source=.\SQLEXPRESS;Initial Catalog=HorstDataProductive;User ID=sa;Password=GuessWhat</ParameterValue>
</MSDeployParameterValue>
</ItemGroup>
</Project>
As you can see I have some additional connection string replacement there that I want to test.
So I execute that last MSBuild-command that I have shown you and it executes without any errors. Instead it says that the web deployment task was successful and that a package has been created in a certain path. Now that is actually the right package. When I import that manually in my IIS it is the result I expect, also the connection string replacement has been done.
But I do not understand why it actually is just creating the package but not deploying it in one run, like in my first command.
Can someone explain?
(Or even better, what do I have to do to make it also deploy that package immediately)
You need to specify the VS version.
http://www.asp.net/mvc/tutorials/deployment/visual-studio-web-deployment/command-line-deployment
msbuild /P:DeployOnBuild=True /P:VisualStudioVersion=11.0 /P:PublishProfile=Dev.pubxml
Don't forget to allow untrusted certs if you're using a 'fake' internal certificate
Looks like you're missing the deploy target.. it's got all the necessary info, but doesn't know what you want it to do. Try this;
msbuild D:\PathToFile\DeployDBVariation01\DeployDBVariation01\DeployDBVariation01.csproj
/p:DeployOnBuild=true;DeployTarget=MSDeployPublish;AllowUntrustedCertificate=true;PublishProfile=ReleaseLocal

MSBuild Web Deploy not updating connection strings

I am currently trying to get my deployment process up and running on my production server. Currently I am using the web deploy and publish profiles to achieve this, and I have everything working correctly, apart from the updating of connection strings to suit the production server.
I am using:
msbuild myProj.csproj /p:DeployOnBuild=true;PublishProfile=myProfile;Configuration=Release
to create the publish package, and the:
call myProj.deploy.cmd /Y /M:http://myServer/MSDeployAgentService -allowUntrusted /U:user /:Password
So this is working, it packages and then sends it to the server fine, and configures IIS correctly, but points to the wrong database.
My publishing profile looks like:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>MSDeploy</WebPublishMethod>
<SiteUrlToLaunchAfterPublish />
<MSDeployServiceURL>http://myserver</MSDeployServiceURL>
<DeployIisAppPath>Website</DeployIisAppPath>
<RemoteSitePhysicalPath />
<SkipExtraFilesOnServer>True</SkipExtraFilesOnServer>
<MSDeployPublishMethod>RemoteAgent</MSDeployPublishMethod>
<UserName>user</UserName>
<_SavePWD>True</_SavePWD>
<PublishDatabaseSettings>
<Objects xmlns="">
<ObjectGroup Name="DBContext" Order="1" Enabled="False">
<Destination Path="Data Source=server;Initial Catalog=ProductionDB;User ID=user;Password="password"" Name="" />
<Object Type="DbCodeFirst">
<Source Path="DBMigration" DbContext="myproj.Repositories.DBContext, myproj.Repositories" MigrationConfiguration="myproj.Repositories.Migrations.Configuration, myproj.Repositories" Origin="Configuration" />
</Object>
</ObjectGroup>
<ObjectGroup Name="DefaultConnection" Order="2" Enabled="False">
<Destination Path="Data Source=server;Initial Catalog=ProductionDB;User ID=user;Password="password"" Name="" />
<Object Type="DbDacFx">
<PreSource Path="Data Source=localhost;Initial Catalog=devDB;User ID=user;Password="password"" includeData="False" />
<Source Path="$(IntermediateOutputPath)AutoScripts\DefaultConnection_IncrementalSchemaOnly.dacpac" dacpacAction="Deploy" />
</Object>
<UpdateFrom Type="Web.Config">
<Source MatchValue="Data Source=localhost;Initial Catalog=devDB;User Id=user;Password=password" MatchAttributes="$(UpdateFromConnectionStringAttributes)" />
</UpdateFrom>
</ObjectGroup>
</Objects>
</PublishDatabaseSettings>
</PropertyGroup>
<ItemGroup>
<MSDeployParameterValue Include="$(DeployParameterPrefix)DBContext-Web.config Connection String">
<ParameterValue> Data Source=server;Initial Catalog=ProductionDB;User ID=user;Password="password"</ParameterValue>
</MSDeployParameterValue>
<MSDeployParameterValue Include="$(DeployParameterPrefix)DefaultConnection-Web.config Connection String">
<ParameterValue>Data Source=server;Initial Catalog=ProductionDB;User ID=user;Password="password"</ParameterValue>
</MSDeployParameterValue>
</ItemGroup>
</Project>
Annoyingly this works fine when Publishing directly from VS2012, just not via command line. Is there a switch or option I am missing from my msbuild call maybe?
It is not working correctly as in my myProj.SetParameters.xml file, the connection strings shown in there are wrong. If I manually change these to the correct connection strings, then the web.xml file is correct on the production server once deployed. How do I get the correct string into my SetParameters file? Any help would be greatly appreciated.
In the end to get around this, in Visual Studio I created a Parameters.xml file in the root of project which holds the values of the connection strings to be used on the production server. These are picked up and used instead of the default values.
The Parameters.xml file looks like:
<?xml version="1.0" encoding="utf-8" ?>
<parameters>
<parameter name="DefaultConnection-Web.config Connection String"
description=""
defaultValue=""tags="" />
Just add as many as you require and obviously populate the attributes as required
My DefaultConnection was not updating either. It turned out that I had to delete the MyProject > PublishProfiles .pubxml file.
Then when attempting to publish the newly built project it asked me to connect to azure and download the publishing profile.
Even though that wizard has a checkbox with the option to turn off overriding the DefaultConnection string with the one pulled down with the publishing profile, unchecking it had no effect. It continued to overwrite the string.
So in the azure control panel (portal) I clicked Websites > My Website > Configure
Scroll down to connection strings and you can show the hidden connection string. I just removed it by hitting the x and then hardcoded the correct one in my web config.
I then removed the .pubxml again and went through the wizard again. Now there is not connectionstring being pulled down with the publish profile.
My Publish Profile .pubxml file (found in Project\Properties\PublishProfiles) had become corrupt with extra duplicate "DefaultConnection-Web.config Connection String" nodes. The connection string updated correctly after I deleted the extra nodes.

MSBuild: Writing and calling a Custom Task, but MSBuild thinks I need a TaskFactory

I'm getting into MSBuild to handle various targets of projects and I'm finding it to be quite flexible. (It's also helping me understand the possibilities of our CI system, too)
I need to get the current SVN revision of the project, for which I have written a custom task that calls SubWCRev and parses the output.
I reference this using the element:
<UsingTask TaskName="xxx.Elements.Build.MSBuildTasks.SubWCRev" AssemblyFile="D:\dev\xxx_presentation\Build\xxx.Elements.Build.dll">
<ParameterGroup>
<LastCommittedRevision ParameterType="System.Int" Required="False" Output="True" />
<MixedRevisionRangeMinimum ParameterType="System.Int" Required="False" Output="True" />
<MixedRevisionRangeMaximum ParameterType="System.Int" Required="False" Output="True" />
<HasLocalModifications ParameterType="System.Boolean" Required="False" Output="True" />
</ParameterGroup>
</UsingTask>
I then execute the task ...
<Target Name="Version" BeforeTargets="BuildDatabase">
<xxx.Elements.Build.MSBuildTasks.SubWCRev WorkingCopyDir="$(ProjectDir)..">
<Output TaskParameter="LastCommittedRevision" ItemName="LastCommittedRevision" />
<Output TaskParameter="MixedRevisionRangeMinimum" ItemName="MixedRevisionRangeMinimum" />
<Output TaskParameter="MixedRevisionRangeMaximum" ItemName="MixedRevisionRangeMaximum" />
<Output TaskParameter="HasLocalModifications" ItemName="HasLocalModifications" />
</xxx.Elements.Build.MSBuildTasks.SubWCRev>
<Message Text="Revision is #(LastCommittedRevision)" />
</Target>
My problem is that MSBuild insists I use the TaskFactory attribute, which this document says is optional. And I'm also seeing that TaskFactory is particularly for Inline Tasks, which I am not interested in.
The error message is:
The required attribute "TaskFactory" is empty or missing from the element UsingTask.
Where am I going wrong?
(And by the way, I'm finding MSBuild Sidekick 3 to be excellent and reducing the resistance of what can become a pretty complicated script.)
That attribute is optional when you are specifying UsingTask in the traditional manner to just point to a task in an assembly:
<UsingTask
TaskName="MyCustomTask"
AssemblyFile="$(PathToTasks)/MyCustomTasks.dll"
/>
When specifying an inline task, the attribute is no longer optional. You then use:
<UsingTask
TaskName="EnableAllPropertyFunctions"
TaskFactory="CodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<ParameterGroup>...
<Task>...
</UsingTask>
What you are doing appears to mix both of those. If you are using a task from the built assembly "D:\dev\xxx_presentation\Build\xxx.Elements.Build.dll", then you shouldn't be specifying the ParameterGroup, MSBuild knows how to discover the parameters, and that it is present in your declaration implies that MSBuild should be trying to find the rest of the inline task.

NAnt <msbuild> custom output directory

I'm new to NAnt and have been able to create a <target> which
1) Deletes any code from the current folder
2) Exports fresh code from SVN
3) Builds the code in the default directory which is the PrecompiledWeb folder (its a web app)
Here it is:
<target name="export" description="export code from svn">
<delete dir="${Delete.Dir}"></delete>
<exec program="svn" commandline="export ${MySVN.Repos} ${MySVN.Dest}" />
<msbuild project="${Solution.Filename}">
<property name="Configuration" value="Release"/>
</msbuild>
</target>
I want to specify a custom output directory (other than "PrecompiledWeb"). Is this possible and could you please show me the necessary tag/property?
Thank you!
EDIT
Thanks to Scott and Si, I'm getting closer to a solution, but I still don't have anything that works. There comments led me to this article on MSBuild's Output Path Property. Using their code:
<?xml version="1.0"?>
<project name="test" default="build" basedir="." xmlns="http://nant.sf.net/schemas/nant-0.84.win32.net-1.0.xsd">
<target name="build">
<exec program="${framework::get-framework-directory('net-3.5')}/msbuild.exe">
<arg value="${Full.Path}\Code\MySolution.sln" />
<arg value="/p:OutputPath=${Full.Path}\Output\" />
</exec>
</target>
</project>
This will sucessfully run; however, in my solution which contains a web site and a class library, it publishes the class library dll to the specified output path, but it still publishes the actual web site to the default PrecompiledWeb folder.
Does anyone have any suggestions for how to change the PrecompiledWeb folder path from NAnt?
Thanks again to everyone who's helped!
Edit 2 Final Solution
Here is what I finally was able to get working (updated for .net 4):
<exec program="${framework::get-framework-directory('net-4.0')}/msbuild.exe">
<arg value="${Full.Path}\Code\MySolution.sln" />
<arg value="/t:Rebuild" />
<arg value="/t:ResolveReferences" />
<arg value="/t:_CopyWebApplication" />
<arg value="/p:OutDir=${Build.Output}bin\" />
<arg value="/p:WebProjectOutputDir=${Build.Output}" />
<arg value="/p:Configuration=Release" />
</exec>
One can specify and override some of properties for msbuild. In order to specify the output directory, override the OutputDir property.
<target name="export" description="export code from svn">
<delete dir="${Delete.Dir}" />
<exec program="svn" commandline="export ${MySVN.Repos} ${MySVN.Dest}" />
<msbuild project="${Solution.Filename}">
<property name="Configuration" value="Release"/>
<property name="OutputDir" value="${Output.Dir}"/>
</msbuild>
</target>
Just had a quick peek at a project, does OutputPath instead of OutputDir help?
Another option might be a web deployment project, which I like because it calls aspnet_compiler as well as the C# compiler, so it picks up issues which you may otherwise miss until deployment.
A build script for one of our projects uses this command to publish a web application:
msbuild.exe /t:_CopyWebApplication /p:Configuration=Release /p:OutDir=.\..\published\ /p:WebProjectOutputDir=.\..\published
(The current directory is set to the web app's project directory at this point, which is why no .csproj file is specified. The entire solution has already been rebuilt earlier in the script.)
By the sound of it, WebProjectOutputDir might be the property you need.
/t:_CopyWebApplication may also be important. I've not used NAnt so I don't know if you can pass this parameter with the msbuild task. You may need to use an exec task, like in this example: http://www.netomatix.com/development/wapwithnant.aspx. This example appears to rebuild and copy all in one go.
When using the task, the correct property name is OutDir, not OutputDir:
<msbuild project="${Solution.Filename}">
<property name="Configuration" value="Release"/>
<property name="OutDir" value="${Output.Dir}"/>
</msbuild>
A source of confusion is that you're blending two distinct build systems. Your NAnt target is delegating all the work of figuring out how to publish your web application to the solution file, hence by extension to the csproj files it references.
csproj files are MsBuild files, so you should probably look there for how to direct your project output. This post by dave^2 might be helpful on that issue.
You can publish your web application wherever you want using NAnt, provided it's doing the publishing. You can do the same with MsBuild. The cause of your quandary is that NAnt is not doing the publishing in this case, and you're letting the csproj file determine the location of your web directory. So either bypass the csproj file and have NAnt (or MsBuild) publish the code; or modify the csproj file to publish the web application where you want; or make a second location for your web application and publish it there as well using your build tool.
AFAIK, those options are exhaustive.
Hmm, don't know how to do it with MSBuild in Nant, but using NAnt, I've done it previously like this:
<solution solutionfile="${build.dir}\solution.sln">
<webmap>
<map url="http://localhost/somdir/project.csproj"
path="c:\inetpub\wwwroot\somelocaldir" />
<webmap>
</solution>
But then, you're using the NAnt 'solution' task offcourse instead of using MSBuild directly.
edit:
I'm also having a look at some msbuild options;
If you set OutDir & OutputPath to the same value, what happens ?
Try something like this:
<property name="nant.settings.currentframework" value="net-3.5"/>
<msbuild project="${Solution.Filename}">
<property name="Configuration" value="Release"/>
<property name="OutDir" value="${Full.Path}\Output\\"/>
<property name="WebProjectOutputDir" value="${Full.Path}\Output\Web\\"/>
</msbuild>