Can I get RavenDB to write to Seq using the NLog WebService target? - ravendb

I'm trying to get RavenDB 3.0 log messages into Seq.
Seq supports posting of raw events using JSON: http://docs.getseq.net/docs/posting-raw-events
RavenDB uses NLog for logging. NLog supports a WebService target: https://github.com/NLog/NLog/wiki/WebService-target
My attempt so far is this:
<target type='WebService'
name='Seq'
url='http://localhost:5341/api/events/raw'
protocol='JsonPost'
encoding='UTF-8'>
<layout xsi:type="JsonLayout">
<attribute name='#t' layout="${longdate}" >
<attribute name='#mt' layout="${message}" >
</layout>
</target>
The full NLog.config file is:
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.netfx35.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target
xsi:type="AsyncWrapper"
name="AsyncLog">
<target xsi:type="SplitGroup">
<!-- create log files with a max size of 256 MB -->
<target
name="File"
xsi:type="File"
archiveAboveSize="268435456"
fileName="${basedir}\Logs\${shortdate}.log">
<layout xsi:type="CsvLayout">
<column name="time" layout="${longdate}" />
<column name="logger" layout="${logger}"/>
<column name="level" layout="${level}"/>
<column name="database" layout="${mdc:item=database}"/>
<column name="threadid" layout="${threadid}" />
<column name="message" layout="${message}" />
<column name="exception" layout="${exception:format=tostring}" />
</layout>
</target>
<target type='WebService'
name='Seq'
url='http://localhost:5341/api/events/raw'
protocol='JsonPost'
encoding='UTF-8'>
<layout xsi:type="JsonLayout">
<attribute name='#t' layout="${longdate}" >
<attribute name='#mt' layout="${message}" >
</layout>
</target>
</target>
</target>
<target
xsi:type="AsyncWrapper"
name="AsyncConflictLog">
<target xsi:type="SplitGroup">
<!-- create log files with a max size of 256 MB -->
<target
name="File"
xsi:type="File"
archiveAboveSize="268435456"
fileName="${basedir}\Logs\${shortdate}.conflicts.log">
<layout xsi:type="CsvLayout">
<column name="time" layout="${longdate}" />
<column name="logger" layout="${logger}"/>
<column name="level" layout="${level}"/>
<column name="database" layout="${mdc:item=database}"/>
<column name="threadid" layout="${threadid}" />
<column name="message" layout="${message}" />
<column name="exception" layout="${exception:format=tostring}" />
</layout>
</target>
</target>
</target>
</targets>
<rules>
<!--<logger name="Raven.Bundles.Replication.Plugins.*" writeTo="AsyncConflictLog" minlevel="Debug"/>-->
<logger name="Raven.*" writeTo="AsyncLog" minlevel="Trace"/>
</rules>
</nlog>
I'm having problems getting it working - I think my layout is invalid but I'm not getting any errors from RavenDB/NLog so it's very hard to work out what it doesn't like.
Has anyone done this or can you see what might be wrong?

Related

Is there any similar kind of configure to rolingStyle="once" of log4net is available for NLog?

I am using log4net currently and on every hour log file archive is being performed.
Now I am changing log4net to NLog
Is there similar setting available in NLog Like rolingStyle="once"? which was configure setting available in log4net.
For example earlier while using log4net the files created were used to be like:
LogFile.log
LogFile.log.1 <-last archive file
Following is configuration I used in log4net and I want to use the exact configure settings so that archived file naming should remains as it was in log4net:
<appender name="Work" type="RMM.Common.Logger.LogFileRollingAppender, Common">
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<dateTimeStrategy type="log4net.Appender.RollingFileAppender+UniversalDateTime" />
<file type="log4net.Util.PatternString" value="%property{EdgeAPILogPath}\WebAPI_Work.log" />
<param name="AppendToFile" value="true"/>
<rollingStyle value="Once" />
<rollingStyle value="Composite" />
<datePattern value=".yyyyMMdd-HH" />
<maxSizeRollBackups value="300" />
<maximumFileSize value="20MB" />
<Encoding value="UTF-8" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%utcdate{yyyy/MM/dd HH:mm:ss,fff} [%-5p] [%3t] %m%n" />
</layout>
<filter type="log4net.Filter.LevelRangeFilter">
<levelMin value="DEBUG" />
<levelMax value="FATAL" />
</filter>
</appender>
You can:
Use fileName="${basedir}/logs/${cached:${date:format=yyyy-MM-dd HH_mm_ss}}.log" as a way to ensure one log file per application instance.
Use archiveFileName="${archiveLogDirectory}/LogFile.log.{####}" to append numbers at the end (feel free to add or remove # as required, depending on your maxArchiveFiles).
Use archiveNumbering="Sequence" to achieve the order you want (higher numbers = newer logs).
Source: this piece of documentation and some personal experience.
Hopefully this basic example will help you getting closer to your final target:
<?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"
internalLogLevel="Error"
internalLogFile="./internal-nlog.txt"
throwExceptions="true">
<variable name="logDirectory" value="./logs"/>
<variable name="archiveLogDirectory" value="./logs/archive"/>
<targets>
<target name="errors"
xsi:type="File"
fileName="${logDirectory}/${cached:${date:format=yyyy-MM-dd HH_mm_ss}}.log"
archiveFileName="${archiveLogDirectory}/LogFile.log.{#}"
maxArchiveFiles="9"
archiveEvery="Hour"
archiveNumbering="Sequence"
/>
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="errors"/>
</rules>
</nlog>
Not an expert on log4net, but it sounds like that rolingStyle="once" is the same as NLog FileTarget ArchiveOldFileOnStartup. So maybe something like this:
<nlog>
<variable name="EdgeAPILogPath" layout="${basedir}" />
<targets>
<target xsi:type="file" name="work"
fileName="${EdgeAPILogPath}/WebAPI_Work.log"
encoding="utf-8"
archiveNumbering="DateAndSequence"
archiveFileName="${EdgeAPILogPath}/WebAPI_Work.{#}.log"
archiveDateFormat="yyyyMMdd-HH"
archiveEvery="Hour"
archiveAboveSize="20000000"
archiveOldFileOnStartup="true"
maxArchiveFiles="300" />
</targets>
<rules>
<logger name="*" minLevel="Debug" writeTo="work" />
</rules>
</nlog>
See also: https://github.com/NLog/NLog/wiki/FileTarget-Archive-Examples

Apache Ant build.xml: Compile failed; see the compiler error output for details

Please help, errors occur when I run build with ant, and I'm new to apache ant.
My project composes of two modules, this build.xml is my main project build file, and dependency module is set within the path label.
My build.xml:
<?xml version="1.0" encoding="utf-8"?>
<project name="GameServer" basedir=".">
<property name="build.dir" value="bin" />
<property name="lib.dir" value="lib" />
<property name="dist.dir" value="dist" />
<property name="source.dir" value="src" />
<property name="web.dir" value="WebContent" />
<property name="TODAY" value="2019-09-10"/>
<path id="classpath">
<fileset dir="${lib.dir}">
<include name="**/*.jar" />
</fileset>
<path location="D:\backend\worldAndBattle\trunk\worldAndBattle" />
</path>
<!-- 初始化 -->
<target name="init" description="Prepare for build">
<mkdir dir="${dist.dir}" />
<mkdir dir="${build.dir}" />
</target>
<!-- 清理 -->
<target name="clean" description="Clean all build products">
<delete dir="${dist.dir}" quiet="true"/>
<delete dir="${build.dir}" quiet="true"/>
</target>
<!-- 编译代码 -->
<target name="compile" description="Compile application" depends="clean, init">
<javac srcdir="${source.dir}"
destdir="${build.dir}"
includes="**/*.java"
debug="on"
deprecation="on"
source="1.7"
includeAntRuntime="false">
<classpath refid="classpath" />
</javac>
</target>
<!-- 打包sql -->
<target name="sql">
<jar destfile="${build.dir}/sql.jar">
<fileset dir="${source.dir}"
includes="**/sql.xml,
**/*.properties"
/>
<manifest>
<attribute name="Author" value="${user.name}" />
<attribute name="Implementation-Date" value="${TODAY}" />
</manifest>
</jar>
</target>
<!-- 打包game -->
<target name="game" depends="compile, sql" >
<jar destfile="${dist.dir}/game.jar">
<fileset dir="${build.dir}"
includes="**/*"
excludes="com/bianfeng/game/hotswap/*,
**/*Test.class,
**/Foo.class,
**/applicationContext.xml, **/*.js, log4j.properties, logback.xml, conf.xml,
**/sql.xml"
/>
<fileset dir="${source.dir}"
includes="**/*.properties"
/>
<manifest>
<attribute name="Author" value="${user.name}" />
<attribute name="Implementation-Date" value="${TODAY}" />
<attribute name="Main-Class" value="com.bianfeng.game.Main" />
</manifest>
</jar>
</target>
<!-- 打包game -->
<target name="game-with-application" depends="compile, sql" >
<jar destfile="${dist.dir}/game.jar">
<fileset dir="${build.dir}"
includes="**/*"
excludes="com/bianfeng/game/hotswap/*,
**/*Test.class,
**/Foo.class,
**/*.js, log4j.properties, logback.xml, conf.xml,
**/sql.xml"
/>
<manifest>
<attribute name="Author" value="${user.name}" />
<attribute name="Implementation-Date" value="${TODAY}" />
</manifest>
</jar>
</target>
<target name="game-cross" depends="compile, sql" >
<jar destfile="${dist.dir}/game-cross.jar">
<fileset dir="${build.dir}"
includes="**/*"
excludes="**/*Test.class,
**/Foo.class,
**/*.js, log4j.properties, logback.xml, conf.xml,
**/sql.xml,
**/*Action.class,
**/*Dao.class
"
/>
<manifest>
<attribute name="Author" value="${user.name}" />
<attribute name="Implementation-Date" value="${TODAY}" />
</manifest>
</jar>
</target>
</project>
and, I am attaching an image with my errors.
When I run compile, I get errors. And I don't know what should I do?

Ant Build Test Target

I'm working with ant for the first time, read lots of tutorials and examples, and still cant make this works. Every target works, but with test im getting
"Test TestMaze failed (crashed)."
I've tried to change lot of things (using lot of examples), still nothing. Can anyone tell me where is the problem please? Thanks a lot.
<?xml version="1.0"?>
<project name="Maze" default="default" basedir=".">
<property name="src.dir" location="src" />
<property name="build.dir" location="build" />
<property name="dist.dir" location="dest-server" />
<property name="test.dir" location="test" />
<property name="test.report.dir" location="testreport" />
<target name="clean">
<delete dir="${build.dir}" />
<delete dir="${dist.dir}" />
<delete dir="${test.report.dir}" />
</target>
<path id="junit.class.path">
<pathelement location="lib/junit-4.10.jar" />
<pathelement location="${build.dir}" />
</path>
<target name="compile" depends="clean">
<mkdir dir="${build.dir}" />
<mkdir dir="${dist.dir}" />
<javac srcdir="${src.dir}" destdir="${build.dir}" />
<javac srcdir="${test.dir}" destdir="${build.dir}">
<classpath refid="junit.class.path" />
</javac>
<jar destfile="${dist.dir}\Maze.jar" basedir="${build.dir}">
<manifest>
<attribute name="Main-Class" value="maze.tape.Commands" />
</manifest>
</jar>
</target>
<target name="test" depends="compile">
<junit printsummary="on" fork="true" haltonfailure="yes">
<classpath refid="junit.class.path" />
<formatter type="xml" />
<batchtest todir="${test.report.dir}">
<fileset dir="${test.dir}">
<include name="**/*Test*.java" />
</fileset>
</batchtest>
</junit>
</target>
<target name="run" depends="compile">
<java jar="dest-server/Maze.jar" fork="true"/>
</target>
</project>
Your test target is generating an xml file because you are using:
<formatter type="xml" />
when the attribute usefile is not used, the default value will be set and in this case, the value is "true".
You can set the attribute to false and the output will be displayed in the console.

How can I insert lines into a file in an MSBuild Task?

I'm trying to insert some text into a file on the second line of the text. I've currently got it inserting the text at the top by using ReadLinesFromFile. Is there a way to break the list I get back from that into 2 pieces so I can insert on the second line?
What I have now:
<Target>
<ReadLinesFromFile File="targetfile.txt">
<Output TaskParameter="Lines" ItemName="TargetFileContents"/>
</ReadLinesFromFile>
<WriteLinesToFile File="targetfile.txt" Lines="$(TextToInsert)" Overwrite="true"/>
<WriteLinesToFile File="targetfile.txt" Lines="#(TargetFileContents)" Overwrite="false"/>
</Target>
It's a bit of a sledge hammer with all the scaffolding, but you can write a task into a project file (or included file, which often has the .targets extension):
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTarget="InsertLine">
<Target Name="InsertLine">
<InsertIntoFile FilePath="test.txt" LineNumber="999" Text="Test complete" />
<InsertIntoFile FilePath="test.txt" LineNumber="1" Text="2" />
<InsertIntoFile FilePath="test.txt" LineNumber="2" Text="3" />
<InsertIntoFile FilePath="test.txt" LineNumber="1" Text="1" />
<InsertIntoFile FilePath="test.txt" LineNumber="1" Text="Testing the 2MC" />
</Target>
<UsingTask
TaskName="InsertIntoFile"
TaskFactory="CodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll" >
<ParameterGroup>
<FilePath ParameterType="System.String" Required="true" />
<LineNumber ParameterType="System.Int32" Required="true" />
<Text ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
<Using Namespace="System" />
<Using Namespace="System.IO" />
<Code Type="Fragment" Language="cs">
<![CDATA[
// By tradition, text file line numbering is 1-based
var lines = File.Exists(FilePath)
? File.ReadAllLines(FilePath).ToList()
: new List<String>(1);
lines.Insert(Math.Min(LineNumber - 1, lines.Count), Text);
File.WriteAllLines(FilePath, lines);
return true;
]]>
</Code>
</Task>
</UsingTask>
</Project>

NAnt resource linking / building

I have almost cracked this NAnt thing, and all I can say is Visual Studio has certainly "hidden" a lot of things behind the covers when it comes to compiling.
I have my VB.NET app compiling successfully now via NAnt, however it does not run, it comes up with the error:
Could not find any resources appropriate for the specified culture or the neutral culture.
Make sure "APP3.Resource.resources" was correctly embedded or linked into assembly "APP3" at compile time, or that all the satellite assemblies required are loadable and fully signed.
When I compile and run in Visual Studio it all works fine.
The build file includes all the .resx files for all projects being compiled, and I do not get any errors during the NAnt build process.
Any ideas would be appreciated :-)
Oh, and I notice that my EXE is 6kb smaller, so something is obviously missing, and the NAnt process does not seem to create a manifest file either, or all the XML files, I assume that is normal?
<?xml version="1.0"?>
<project name="APP3" default="build" basedir="..\">
<description>APP3 build</description>
<property name="nant.settings.currentframework" value="net-3.5" />
<property name="projectversion" value="3.8.0" />
<property name="project.config" value="debug" />
<target name="init">
<call target="${project.config}" />
</target>
<target name="debug">
<property name="project.config" value="debug" />
<property name="build.debug" value="true" />
<property name="basedir.suffix" value="-debug" />
</target>
<target name="release">
<property name="project.config" value="release" />
<property name="build.debug" value="false" />
<property name="basedir.suffix" value="-release" />
</target>
<target name="clean">
<delete file="${project::get-base-directory()}${project::get-name()}_${projectversion}${basedir.suffix}\APP3_DataClasses.dll" failonerror="false" />
<delete file="${project::get-base-directory()}${project::get-name()}_${projectversion}${basedir.suffix}\classUtilities.dll" failonerror="false" />
<delete file="${project::get-base-directory()}${project::get-name()}_${projectversion}${basedir.suffix}\APP3.exe" failonerror="false" />
</target>
<target name="build-classutilities" depends="init, clean" description="compiles the APP3 utilities class">
<property name="build.dir" value="${project::get-base-directory()}/${project::get-name()}_${projectversion}${basedir.suffix}"/>
<mkdir dir="${build.dir}" />
<vbc target="library" output="${build.dir}/classUtilities.dll" debug="${build.debug}" rootnamespace="classUtilities">
<imports>
<import namespace="Microsoft.VisualBasic" />
<import namespace="System" />
<import namespace="System.Collections" />
<import namespace="System.Collections.Generic" />
<import namespace="System.Data" />
<import namespace="System.Diagnostics" />
<import namespace="System.Linq" />
<import namespace="System.Xml.Linq" />
</imports>
<sources>
<include name="${project::get-base-directory()}/classUtilities/Utilities.vb" />
</sources>
<resources>
<include name="${project::get-base-directory()}/classUtilities/*.resx" />
<include name="${project::get-base-directory()}/classUtilities/My Project/*.resx" />
</resources>
<references>
<include name="System.dll" />
<include name="System.Data.dll" />
<include name="System.Core.dll" />
<include name="System.Xml.dll" />
<include name="System.Xml.Linq.dll" />
</references>
</vbc>
</target>
<target name="build-dataclasses" depends="build-classutilities" description="compiles the APP3 data classes">
<property name="build.dir" value="${project::get-base-directory()}/${project::get-name()}_${projectversion}${basedir.suffix}"/>
<mkdir dir="${build.dir}" />
<vbc target="library" output="${build.dir}/APP3_DataClasses.dll" debug="${build.debug}" rootnamespace="APP3_DataClasses">
<imports>
<import namespace="Microsoft.VisualBasic" />
<import namespace="System" />
<import namespace="System.Collections" />
<import namespace="System.Collections.Generic" />
<import namespace="System.Configuration" />
<import namespace="System.Data" />
<import namespace="System.Diagnostics" />
<import namespace="System.Xml" />
<import namespace="System.Xml.Linq" />
<import namespace="Iesi.Collections" />
</imports>
<sources>
<include name="${project::get-base-directory()}/APP3_DataClasses/**/*.vb" />
</sources>
<resources prefix="APP3_DataClasses">
<include name="${project::get-base-directory()}/APP3_DataClasses/*.resx" />
<include name="${project::get-base-directory()}/APP3_DataClasses/My Project/*.resx" />
<include name="${project::get-base-directory()}/APP3_DataClasses/*.hbm.xml" />
</resources>
<references>
<include name="System.dll" />
<include name="System.Core.dll" />
<include name="System.Xml.dll" />
<include name="System.Xml.Linq.dll" />
<include name="C:\Dev\NHibernate-2.1.2\Required_Bins\Iesi.Collections.dll" />
</references>
</vbc>
</target>
<target name="build" description="compiles the source code" depends="build-dataclasses">
<property name="build.dir" value="${project::get-base-directory()}/${project::get-name()}_${projectversion}${basedir.suffix}"/>
<mkdir dir="${build.dir}" />
<copy file="C:\Dev\NHibernate-2.1.2\Required_Bins\NHibernate.dll" tofile="${build.dir}/NHibernate.dll" />
<copy file="C:\Dev\NHibernate-2.1.2\Required_Bins\Iesi.Collections.dll" tofile="${build.dir}/Iesi.Collections.dll" />
<copy file="C:\Dev\NHibernate-2.1.2\Required_Bins\log4net.dll" tofile="${build.dir}/log4net.dll" />
<copy file="${project::get-base-directory()}/APP3/hibernate.cfg.xml" tofile="${build.dir}/hibernate.cfg.xml" />
<copy file="C:\Dev\LumenWorks.Framework\LumenWorks.Framework.3.8.0\LumenWorks.Framework.IO.dll" tofile="${build.dir}/LumenWorks.Framework.IO.dll" />
<copy file="C:\Program Files (x86)\Microsoft Visual Studio 9.0\Visual Studio Tools for Office\PIA\Office11\Microsoft.Office.Interop.Word.dll" tofile="${build.dir}/Microsoft.Office.Interop.Word.dll" />
<copy file="C:\Program Files (x86)\Microsoft Visual Studio 9.0\Visual Studio Tools for Office\PIA\Office11\office.dll" tofile="${build.dir}/office.dll" />
<copy file="C:\Program Files (x86)\Microsoft Visual Studio 9.0\Visual Studio Tools for Office\PIA\Office11\Microsoft.Vbe.Interop.dll" tofile="${build.dir}/Microsoft.Vbe.Interop.dll" />
<copy file="${project::get-base-directory()}/APP3/app.config" tofile="${build.dir}/APP3.exe.config" />
<copy todir="${build.dir}">
<fileset basedir="C:\Dev\NHibernate-2.1.2\Required_For_LazyLoading\Castle\">
<include name="*.dll" />
</fileset>
</copy>
<vbc target="winexe" output="${build.dir}/APP3.exe" debug="${build.debug}" rootnamespace="APP3">
<imports>
<import namespace="Microsoft.VisualBasic" />
<import namespace="System" />
<import namespace="System.Collections" />
<import namespace="System.Collections.Generic" />
<import namespace="System.Configuration" />
<import namespace="System.Data" />
<import namespace="System.Data.SqlClient" />
<import namespace="System.Diagnostics" />
<import namespace="System.Drawing" />
<import namespace="System.Windows.Forms" />
<import namespace="System.IO" />
<import namespace="System.Xml" />
</imports>
<sources>
<include name="${project::get-base-directory()}/${project::get-name()}/*.vb" />
<include name="${project::get-base-directory()}/${project::get-name()}/classes/*.vb" />
<include name="${project::get-base-directory()}/${project::get-name()}/historical/*.vb" />
<include name="${project::get-base-directory()}/${project::get-name()}/Modules/*.vb" />
<include name="${project::get-base-directory()}/${project::get-name()}/My Project/*.vb" />
</sources>
<resources prefix="APP3" dynamicprefix="true">
<include name="${project::get-base-directory()}/${project::get-name()}/*.resx" />
<include name="${project::get-base-directory()}/${project::get-name()}/My Project/*.resx" />
</resources>
<references>
<include name="Microsoft.VisualBasic.dll" />
<include name="System.dll" />
<include name="System.Data.dll" />
<include name="System.Windows.Forms.dll" />
<include name="System.configuration.dll" />
<include name="System.Drawing.dll" />
<include name="${build.dir}/APP3_DataClasses.dll" />
<include name="${build.dir}/classUtilities.dll" />
<include name="System.Xml.dll" />
<include name="C:\Dev\NHibernate-2.1.2\Required_Bins\Iesi.Collections.dll" />
<include name="C:\Dev\NHibernate-2.1.2\Required_Bins\NHibernate.dll" />
<include name="C:\Dev\NHibernate-2.1.2\Required_Bins\log4net.dll" />
<include name="C:\Dev\LumenWorks.Framework\LumenWorks.Framework.3.8.0\LumenWorks.Framework.IO.dll" />
<include name="C:\Program Files (x86)\Microsoft Visual Studio 9.0\Visual Studio Tools for Office\PIA\Office11\Microsoft.Office.Interop.Word.dll" />
</references>
</vbc>
</target>
I faced the same problem, and then tested each of the assemblies with the program .NET Reflector I've discovered that when a program is compiled from the VS, a resource file Properties\Resources.resx in the assembly has a name appName.Properties.Resources.resources. When you use nAnt
<resources>
<include name="${proj_dir}/Properties/Resources.resx"/>
</ resources>
in the assembly resource file has name Resources.resources .
I solved this problem as follows.
<target name="example">
<copy file="${proj_dir}/Properties/Resources.resx" tofile="${proj_dir}/Properties/appName.Properties.Resources.resx"/>
<csc target="winexe" output="${bin_dir}/appName.exe">
<sources>
<include name="${proj_dir}/*.cs"/>
<include name="${proj_dir}/Properties/*.cs"/>
</sources>
<resources>
<include name="${proj_dir}/Properties/appName.Properties.Resources.resx"/>
</resources>
</csc>
<delete file="${proj_dir}/Properties/appName.Properties.Resources.resx"/>
</target>