fluent / NLog.Targets.Fluentd

Apache License 2.0
44 stars 31 forks source link

Fallback doesn't seem to be working #11

Open burtonr opened 5 years ago

burtonr commented 5 years ago

Logs are being sent to the local fluentd instance just fine, and with the forwarding rules in place, are being transmitted out to the main aggregator instance as well. However, I'm trying to make sure that if the local fluentd is not available for some reason, that the logs will be written to a local file to be gathered manually when we fix the problem.

If I kill the local fluentd instance, so that the connection will fail, the fallback target is not being called and no log file is present in the given directory. Am I missing something, or configured something incorrectly?

Here is my config (I was messing with the timeout and buffer sizes thinking that may have something to do with it) :

var logLayout = new SimpleLayout("${longdate} [${level}] ${message} ${exception}");
var config = new LoggingConfiguration();

var fallbackTarget = new FallbackGroupTarget
{
    Name = "fluentd-fallback",
    ReturnToFirstOnSuccess = false
};

var fluentdTarget = new Fluentd
{
    Name = "fluentd",
    Layout = logLayout,
    NoDelay = true,
    SendTimeout = 1,
    ReceiveTimeout = 1,
    LingerEnabled = false,
    Tag = "new-api"
};

var fileTarget = new FileTarget
{
    Name = "fluentd-file-fallback",
    FileName = "C:\\logs\\fluent-failed.txt",
    Layout = logLayout,
    Encoding = Encoding.UTF8
};

fallbackTarget.Targets.Add(fluentdTarget);
fallbackTarget.Targets.Add(fileTarget);

var bufferWrapper = new BufferingTargetWrapper
{
    Name = "fluentd-buffer",
    OverflowAction = BufferingTargetWrapperOverflowAction.Flush,
    SlidingTimeout = true,
    WrappedTarget = fallbackTarget,
    BufferSize = 1,
    FlushTimeout = 50
};

config.AddTarget("fluentd-buffer", bufferWrapper);
config.AddRuleForAllLevels(bufferWrapper);

var loggerFactory = new LogFactory(config)
{
    ThrowConfigExceptions = true,
    ThrowExceptions = true
};

InternalLogger.LogFile = "C:\\logs\\nlog-internal.txt";
InternalLogger.LogLevel = LogLevel.Debug;

return loggerFactory.GetLogger("burtonr");

I should note that the internal log does appear, so there shouldn't be any issues with the file system permissions. The internal log file looks like this:

2018-12-24 18:17:31.0025 Debug Targets for fluentd-fallback by level:
2018-12-24 18:17:31.0194 Debug Trace => fluentd-fallback
2018-12-24 18:17:31.0345 Debug Debug => fluentd-fallback
2018-12-24 18:17:31.0345 Debug Info => fluentd-fallback
2018-12-24 18:17:31.0506 Debug Warn => fluentd-fallback
2018-12-24 18:17:31.0506 Debug Error => fluentd-fallback
2018-12-24 18:17:31.0665 Debug Fatal => fluentd-fallback
2018-12-24 18:18:05.2545 Debug Targets for burtonr by level:
2018-12-24 18:18:05.2702 Debug Trace => fluentd-buffer
2018-12-24 18:18:05.2702 Debug Debug => fluentd-buffer
2018-12-24 18:18:05.2702 Debug Info => fluentd-buffer
2018-12-24 18:18:05.2858 Debug Warn => fluentd-buffer
2018-12-24 18:18:05.2858 Debug Error => fluentd-buffer
2018-12-24 18:18:05.2858 Debug Fatal => fluentd-buffer
snakefoot commented 5 years ago

You are waiting for #8 to be released officially on nuget (There is also a pending PR #10 that could be nice).

@moriyoshi Maybe the nuget-release can become a late christmas present?