Nlog with MongoDB connection and target - mongodb

I am trying to use a logger that will log into MongoDB, but I can not get it to work. In the same configuration i have set up the loggers to log using an email and file and both work just fine.
Here is my NLog.config 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">
<extensions>
<add assembly="NLog.MongoDB"/>
</extensions>
<!--
See http://nlog-project.org/wiki/Configuration_file
for information on customizing logging rules and outputs.
-->
<targets>
<target xsi:type="File" name="file" fileName="${basedir}/logs/${shortdate}.log"
layout="${longdate} ${uppercase:${level}} ${message}" />
<target xsi:type="Mongo"
name="mongoDefault"
connectionString="mongodb://localhost/nlog"
collectionName="cdss"
cappedCollectionSize="26214400">
<property name="ThreadID" layout="${threadid}" bsonType="Int32" />
<property name="ThreadName" layout="${threadname}" />
<property name="ProcessID" layout="${processid}" bsonType="Int32" />
<property name="ProcessName" layout="${processname:fullName=true}" />
<property name="UserName" layout="${windows-identity}" />
</target>
<target name="TcpOutlet" xsi:type="Chainsaw" address="tcp4://localhost:4505" > </target>
<target name="Email" xsi:type="Mail"
smtpServer="localhost"
smtpPort="25"
smtpAuthentication="None"
enableSsl="false"
from="ssss#sdsdfs"
to="ssss#sdsdfs" html="true"
/>
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="file,TcpOutlet,mongoDefault,Email" />
<logger name="*" minlevel="Error" writeTo="file,TcpOutlet,Email,mongoDefault" />
</rules>
</nlog>
I have installed the Nlog.Mongo nugget also. My database is called nlog. Whatever i do, the loggers do not write in the mongodb. I am using NLogger.

Related

Xml.IsRuleValid is failing after upgrade from CodeEffects 4.3.7.2 to 5

We are trying to upgrade from CodeEffects 4.3.7.2 to 5. However, our existing rule xml fail when executing CodeEffects.Rule.Common.Xml.IsRuleValid. We are just loading the Xml into an XmlDocument and calling Xml.IsRuleValid. This is all existing and working code in CodeEffects 4. Below is the exception thrown.
Value cannot be null. Parameter name: input
at System.Xml.XmlReaderSettings.CreateReader(Stream input, Uri baseUri, String baseUriString, XmlParserContext inputContext)
at System.Xml.XmlReader.Create(Stream input, XmlReaderSettings settings, String baseUri)
at CodeEffects.Rule.Common.RuleXmlValidator.AddSchema(XmlSchemaSet schemas, String schemaName, Assembly assembly)
at CodeEffects.Rule.Common.RuleXmlValidator..ctor()
at CodeEffects.Rule.Common.Xml.IsRuleValid(XmlDocument ruleXml)
Here is a sample xml of a rule now failing in this check. "CustomerSince" and "SystemDate" are DateTime.
<?xml version="1.0" encoding="utf-8"?>
<codeeffects xmlns="http://codeeffects.com/schemas/rule/41" xmlns:ui="http://codeeffects.com/schemas/ui/4">
<rule id="ab686e3c-e896-420c-9f8b-5fd09943c939" webrule="4.3.2.71" utc="2016-12-16T07:49:18.9753" type="CompanyABC.Domain.ICustomer, CompanyABC.Domain.State, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" eval="true">
<definition>
<or>
<condition type="isNull">
<property name="CustomerSince" />
</condition>
<condition type="lessOrEqual">
<property name="CustomerSince" />
<property name="SystemDate" />
</condition>
</or>
</definition>
<format><lines /></format>
</rule>
</codeeffects>
I tried using the CodeEffects 5 Classic MVC Rule Editor and generated the below Xml but I still see the same error.
<?xml version="1.0" encoding="utf-8"?>
<codeeffects xmlns="http://codeeffects.com/schemas/rule/41" xmlns:ui="http://codeeffects.com/schemas/ui/4">
<rule id="aecdeec9-9b06-4cb1-910d-8b62c311c72f" webrule="5.0.12.4" utc="2020-05-11T22:04:19.8510" type="CompanyABC.Domain.ICustomer, CompanyABC.Domain.State, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" eval="true">
<definition>
<or ui:block="true">
<condition type="isNull">
<property name="CustomerSince" />
</condition>
<condition type="lessOrEqual">
<property name="CustomerSince" />
<property name="SystemDate" />
</condition>
</or>
</definition>
<format><lines /></format>
</rule>
</codeeffects>
We are using the following libraries from CodeEffects Downloader:
CodeEffects.Rule.Common.dll (5.0.4.2)
CodeEffects.Rule.Engine.Standard.dll (5.0.9.6)
And below from Nuget packages:
CodeEffects.Rule.Editor.Mvc.dll (5.0.12.4)
CodeEffects.Rule.Editor.Net.dll (5.0.12.4)
Any assistance would be appreciated.
This issue has been fixed in the latest minor version released earlier today.

Service Fabric Explorer Health State Unknown

The node in my partition keeps switching between Health State = OK and Health State = unknown.
Sometimes the node disappears.
I have tried deleting the service, the app and unprovisioning the type, then redeploying, however I get the same problem.
It is a Service Fabric stateful service, and it's running fine locally, the issue I'm having is only in my dev environment.
I'm using 5 nodes.
ServiceManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<ServiceManifest Name="Integration.Optical.ServicePkg"
Version="1.0.0"
xmlns="http://schemas.microsoft.com/2011/01/fabric"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ServiceTypes>
<!-- This is the name of your ServiceType.
This name must match the string used in the RegisterServiceAsync call in Program.cs. -->
<StatefulServiceType ServiceTypeName="Integration.Optical.ServiceType" />
</ServiceTypes>
<!-- Code package is your service executable. -->
<CodePackage Name="Code" Version="1.0.0">
<EntryPoint>
<ExeHost>
<Program>Integration.Optical.Service.exe</Program>
<WorkingFolder>CodePackage</WorkingFolder>
</ExeHost>
</EntryPoint>
<EnvironmentVariables>
<EnvironmentVariable Name="ASPNETCORE_ENVIRONMENT" Value=""/>
<EnvironmentVariable Name="KEYVAULT_ENDPOINT" Value=""/>
</EnvironmentVariables>
</CodePackage>
<!-- Config package is the contents of the Config directoy under PackageRoot that contains an
independently-updateable and versioned set of custom configuration settings for your service. -->
<ConfigPackage Name="Config" Version="1.0.0" />
<Resources>
<Endpoints>
<!-- This endpoint is used by the communication listener to obtain the port on which to
listen. Please note that if your service is partitioned, this port is shared with
replicas of different partitions that are placed in your code. -->
<Endpoint Name="ServiceEndpoint" />
<!-- This endpoint is used by the replicator for replicating the state of your service.
This endpoint is configured through a ReplicatorSettings config section in the Settings.xml
file under the ConfigPackage. -->
<Endpoint Name="ReplicatorEndpoint" />
</Endpoints>
</Resources>
</ServiceManifest>
ApplicationManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<ApplicationManifest xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ApplicationTypeName="Integration.OpticalType" ApplicationTypeVersion="1.0.0" xmlns="http://schemas.microsoft.com/2011/01/fabric">
<Parameters>
<Parameter Name="Integration.Optical.Service_ASPNETCORE_ENVIRONMENT" DefaultValue="" />
<Parameter Name="Integration.Optical.Service_KEYVAULT_ENDPOINT" DefaultValue="" />
<Parameter Name="Integration.Optical.Service_MinReplicaSetSize" DefaultValue="3" />
<Parameter Name="Integration.Optical.Service_PartitionCount" DefaultValue="1" />
<Parameter Name="Integration.Optical.Service_TargetReplicaSetSize" DefaultValue="3" />
</Parameters>
<!-- Import the ServiceManifest from the ServicePackage. The ServiceManifestName and ServiceManifestVersion
should match the Name and Version attributes of the ServiceManifest element defined in the
ServiceManifest.xml file. -->
<ServiceManifestImport>
<ServiceManifestRef ServiceManifestName="Integration.Optical.ServicePkg" ServiceManifestVersion="1.0.0" />
<ConfigOverrides />
<EnvironmentOverrides CodePackageRef="code">
<EnvironmentVariable Name="ASPNETCORE_ENVIRONMENT" Value="[Integration.Optical.Service_ASPNETCORE_ENVIRONMENT]" />
<EnvironmentVariable Name="KEYVAULT_ENDPOINT" Value="[Integration.Optical.Service_KEYVAULT_ENDPOINT]" />
</EnvironmentOverrides>
</ServiceManifestImport>
<DefaultServices>
<!-- The section below creates instances of service types, when an instance of this
application type is created. You can also create one or more instances of service type using the
ServiceFabric PowerShell module.
The attribute ServiceTypeName below must match the name defined in the imported ServiceManifest.xml file. -->
<Service Name="Integration.Optical.Service" ServicePackageActivationMode="ExclusiveProcess">
<StatefulService ServiceTypeName="Integration.Optical.ServiceType" TargetReplicaSetSize="[Integration.Optical.Service_TargetReplicaSetSize]" MinReplicaSetSize="[Integration.Optical.Service_MinReplicaSetSize]">
<UniformInt64Partition PartitionCount="[Integration.Optical.Service_PartitionCount]" LowKey="-9223372036854775808" HighKey="9223372036854775807" />
</StatefulService>
</Service>
</DefaultServices>
</ApplicationManifest>
ApplicationParameters/Cloud.xml:
<?xml version="1.0" encoding="utf-8"?>
<Application xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Name="fabric:/Integration.Optical" xmlns="http://schemas.microsoft.com/2011/01/fabric">
<Parameters>
<Parameter Name="Integration.Optical.Service_ASPNETCORE_ENVIRONMENT" Value="" />
<Parameter Name="Integration.Optical.Service_KEYVAULT_ENDPOINT" Value="" />
<Parameter Name="Integration.Optical.Service_PartitionCount" Value="1" />
<Parameter Name="Integration.Optical.Service_MinReplicaSetSize" Value="1" />
<Parameter Name="Integration.Optical.Service_TargetReplicaSetSize" Value="1" />
</Parameters>
</Application>
Not sure what part of this fixed it. But this is what I did and it's now working:
In ServiceManifest.xml I added HasPersistedState = true:
<StatefulServiceType ServiceTypeName="Integration.Optical.ServiceType" HasPersistedState="true" />
I moved the app configuration code
ServiceRuntime.RegisterServiceAsync...
from Service.RunAsync() to Program.Main()

log4net gmail smtp appender do not sending emails

I'm trying to use SmtpAppender of log4net in order to send log via Gmail. But it's not working - I did not received any email. Internal logging didn't showed any errors, so I'm even not sure is it failed or not.
Here is config:
<appSettings>
<add key="log4net.Internal.Debug" value="true" />
</appSettings>
<system.diagnostics>
<trace autoflush="true">
<listeners>
<add name="tracer"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="D:\\Dev\\Camps\\log4net.log" />
</listeners>
</trace>
</system.diagnostics>
<log4net>
<root>
<level value="ALL" />
<appender-ref ref="SmtpAppender" />
</root>
<appender name="SmtpAppender" type="log4net.Appender.SmtpAppender">
<authentication value="Basic" />
<username value="...#gmail.com" />
<password value="..." />
<to value="...#gmail.com" />
<from value="...#gmail.com" />
<subject value="log4net message from Camps.DAL" />
<smtpHost value="smtp.gmail.com" />
<port value="587"/>
<bufferSize value="1" />
<EnableSsl value="true"/>
<lossy value="false" />
<evaluator type="log4net.Core.LevelEvaluator">
<threshold value="ALL"/>
</evaluator>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%newline%date [%thread] %-5level %logger [%property{NDC}] - %message%newline%newline%newline" />
</layout>
</appender>
</log4net>
It seems you have to use your username instead of your email address:
<username value="...#gmail.com" /> <<---- username, not email address

Fetching data from PostgreSQL database in Mule flow using JDBC transport

I have a Mule flow to fetch data from a table in a PostgreSQL database and convert the data into XML format and write to a file:
<mule ...>
<spring:bean id="Postgres-jdbcDataSource"
class="org.enhydra.jdbc.standard.StandardDataSource" destroy-method="shutdown">
<spring:property name="driverName" value="org.postgresql.Driver" />
<spring:property name="url"
value="jdbc:postgresql://host:port/schema?user=username&password=password" />
</spring:bean>
<jdbc:connector name="Postgres-jdbcConnector"
dataSource-ref="Postgres-jdbcDataSource" pollingFrequency="60000"
transactionPerMessage="false">
<jdbc:query key="read" value="SELECT * FROM tablename" />
</jdbc:connector>
<file:connector name="file_connector" fileAge="500"
streaming="false" pollingFrequency="60000" />
<flow name="Postgres-flow">
<jdbc:inbound-endpoint queryKey="read"
connector-ref="Postgres-jdbcConnector">
<jdbc:transaction action="ALWAYS_BEGIN" />
<property key="receiveMessageInTransaction" value="true" />
</jdbc:inbound-endpoint>
<custom-transformer name="Postgres-transformer"
class="com.example.transformer.DbToXmlTransformer" ignoreBadInput="false"
encoding="UTF-8" />
<file:outbound-endpoint connector-ref="file_connector"
path="/home/path" outputPattern="file.xml" responseTimeout="10000"
encoding="UTF-8" />
</flow>
</mule>
When I run this flow, the flow does not fetch data from DB and write to file. It does not throw any errors or exceptions either. But when I run the same flow for MySQL or SQLServer database, changing driverName and url properties accordingly, the flow works fine.
Any idea why the Postgres database does not work? Probably it requires different DataSource class?
There is also a Postgre data source for mule and you can use it instead of spring beans :
<jdbc:postgresql-data-source name="PostgreSQL_Data_Source" user="your user name" password="your pwd" url="jdbc:postgresql://localhost:5432/TestDB" transactionIsolation="UNSPECIFIED" doc:name="PostgreSQL Data Source"/>
Anyways... , with your existing config you can just check by keeping the JDBC inbound endpoint in a poll component and place a logger before File outbound to check the payload value.. If it gets payload value in logger ..that means it is fetching the value ..Let me know if it works ... you can try the following :-
<mule ...>
<spring:bean id="Postgres-jdbcDataSource"
class="org.enhydra.jdbc.standard.StandardDataSource" destroy-method="shutdown">
<spring:property name="driverName" value="org.postgresql.Driver" />
<spring:property name="url"
value="jdbc:postgresql://host:port/schema?user=username&password=password" />
</spring:bean>
<jdbc:connector name="Postgres-jdbcConnector"
dataSource-ref="Postgres-jdbcDataSource" pollingFrequency="60000"
transactionPerMessage="false">
<jdbc:query key="read" value="SELECT * FROM tablename" />
</jdbc:connector>
<file:connector name="file_connector" fileAge="500"
streaming="false" pollingFrequency="60000" />
<flow name="Postgres-flow">
<poll frequency="1000" doc:name="Poll">
<jdbc:inbound-endpoint queryKey="read"
connector-ref="Postgres-jdbcConnector">
<jdbc:transaction action="ALWAYS_BEGIN" />
<property key="receiveMessageInTransaction" value="true" />
</jdbc:inbound-endpoint>
</poll>
<!-- You can also use object to xml transformer if you are not using any custom transformer -->
<!--<mulexml:object-to-xml-transformer doc:name="Object to XML"/> -->
<custom-transformer name="Postgres-transformer"
class="com.example.transformer.DbToXmlTransformer" ignoreBadInput="false"
encoding="UTF-8" />
<logger message="Payload :- #[message.payload]" level="INFO" doc:name="Logger"/>
<file:outbound-endpoint connector-ref="file_connector"
path="/home/path" outputPattern="file.xml" responseTimeout="10000"
encoding="UTF-8" />
</flow>
</mule>
For more find the reference here for Postgre Database with Mule :- http://www.dotnetfunda.com/articles/show/2068/using-mule-studio-to-read-data-from-postgresqlinbound-and-write-it-to

Deploying on remote JBoss 6.x with Cargo

I'm trying to setup an Ant Target to perform a remote deploy on a JBoss 6.x server, using Cargo.
Here is my target description:
<target name="deploy" depends="install-cargo,make-war">
<input message="Enter username for deployment..."
addproperty="deploy.username" />
<input message="Enter password for ${deploy.username}..."
addproperty="deploy.password" >
<handler type="secure" />
</input>
<cargo containerId="jboss6x" action="redeploy" type="remote">
<configuration type="runtime">
<property name="cargo.hostname" value="${deploy.host}" />
<property name="cargo.servlet.port" value="${deploy.host}" />
<property name="cargo.remote.username" value="${deploy.username}" />
<property name="cargo.remote.password" value="${deploy.password}" />
<deployable type="war" file="${dist.dir}/${ant.project.name}.war">
<property name="context" value="${ant.project.name}" />
</deployable>
</configuration>
</cargo>
Every jar inside [jboss.home]/client and [jboss.home]/lib is inside cargo.tasks classpath but when i try to execute the Target I get this error:
javax.security.auth.login.LoginException: impossibile trovare la classe LoginModule: org.jboss.security.ClientLoginModule
That is Java cannot find class org.jboss.security.ClientLoginModule (by the way: this class is located inside jbosssx.jar in [jboss.home]/lib).
Am I missing some jar? Do I need to configure something for jaas? Thanks for your help.