private static void AddChainsawLogging(LoggingConfiguration configuration) { const string TargetName = "Chainsaw"; var target = new ChainsawTarget() { Name = TargetName, Address = "udp://127.0.0.1:7071" }; var rule = new LoggingRule("*", LogLevel.Trace, target); configuration.AddTarget(TargetName, target); configuration.LoggingRules.Add(rule); }
static void Main(string[] args) { ChainsawTarget target = new ChainsawTarget(); target.Address = "udp://localhost:4000"; NLog.Config.SimpleConfigurator.ConfigureForTargetLogging(target, LogLevel.Debug); Logger logger = LogManager.GetLogger("Example"); logger.Trace("log message 1"); logger.Debug("log message 2"); logger.Info("log message 3"); logger.Warn("log message 4"); logger.Error("log message 5"); logger.Fatal("log message 6"); }
public Log() { var config = new LoggingConfiguration(); var consoleTarget = new ColoredConsoleTarget { Layout = "${date:format=HH\\:MM\\:ss} ${logger} ${message}" }; var chainsawTarget = new ChainsawTarget { Address = "udp://127.0.0.1:7071", Name = "chainsaw", Layout = "Log4JXmlEventLayout" }; config.AddTarget("console", consoleTarget); config.AddTarget("chainsaw", chainsawTarget); config.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, consoleTarget)); config.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, chainsawTarget)); LogManager.Configuration = config; Logger = LogManager.GetCurrentClassLogger(); }
/// <summary> /// Adds network logging. /// </summary> public static void UseLog2ConsoleLogging() { ChainsawTarget target = new ChainsawTarget(); target.AppInfo = "Roadkill"; target.Address = "udp://127.0.0.1:7071"; AddNLogTarget(target, "RoadkillLog2Console"); }