public LogzioThroughNLogLoggingService(IConfiguration config, NLogProper.Config.LoggingConfiguration nlogConfig = null) { if (nlogConfig.AllTargets.FirstOrDefault((t) => (t.GetType() == typeof(Logzio.DotNet.NLog.LogzioTarget))) == null) { nlogConfig.AddTarget("Logzio", new LogzioTarget { Token = config.GetStringOrError("LOGGING_LOGZIO_TOKEN") }); NLogProper.LogLevel minLevel, maxLevel; string value; minLevel = (value = config.GetString("LOGGING_LOGZIO_MINLEVEL")) == null ? NLogProper.LogLevel.Error : NLogProper.LogLevel.FromString(value); maxLevel = (value = config.GetString("LOGGING_LOGZIO_MAZLEVEL")) == null ? NLogProper.LogLevel.Fatal : NLogProper.LogLevel.FromString(value); nlogConfig.AddRule(minLevel, maxLevel, "Logzio"); } this.logger = new CODNLogLoggingService(nlogConfig); }
public string LoggerMessage_IsCorrect(string name, Action <Microsoft.Extensions.Logging.ILogger> logAction) { var config = new global::NLog.Config.LoggingConfiguration(); var memoryTarget = new global::NLog.Targets.MemoryTarget(); memoryTarget.Layout = "${message}"; // Message format config.AddRuleForAllLevels(memoryTarget); LogManager.Configuration = config; ILoggerFactory loggerFactory = new NLogLoggerFactory(new NLogProviderOptions()); Microsoft.Extensions.Logging.ILogger logger = loggerFactory.CreateLogger("test"); logger.Here(logAction); string result = memoryTarget.Logs.First(); logger = null; memoryTarget.Dispose(); LogManager.Shutdown(); return(result); }
public CODNLogLoggingService(global::NLog.Config.LoggingConfiguration nlogConfig = null) { this.nlogFactory = new global::NLog.LogFactory(nlogConfig); }