NLog allows you to log to multiple targets via a configuration file. Don't forget to set ignoreFailures to true to ensure that any install/uninstall failures are ignored:
<?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">
<targets>
<target name="logfile" xsi:type="File" />
<target name="db" xsi:type="Database" />
</targets>
<rules>
<logger name="*" levels="Info" writeTo="logfile,db" />
</rules>
</nlog>
See database target in the NLog documentation for more information
Edit: You could also create a custom target in order to achieve this in code:
using NLog;
using NLog.Targets;
namespace MyNamespace
{
[Target("MyFirst")]
public sealed class MyFirstTarget: TargetWithLayout
{
public MyFirstTarget()
{
this.Host = "localhost";
}
[Required]
public string Host { get; set; }
protected override void Write(LogEventInfo logEvent)
{
string logMessage = this.Layout.Render(logEvent);
SendTheMessageToRemoteHost(this.Host, logMessage);
}
private void SendTheMessageToRemoteHost(string host, string message)
{
// Detect your database state here or do something else with the error.
}
}
}
and use it with:
<nlog>
<extensions>
<add assembly="MyAssembly"/>
</extensions>
<targets>
<target name="a1" type="MyFirst" host="localhost"/>
</targets>
<rules>
<logger name="*" minLevel="Info" appendTo="a1"/>
</rules>
</nlog>
See this page for more information.