Наследование: TargetWithLayout
        public void Execute()
        {
            string key = ConfigurationManager.AppSettings["LOGENTRIES_ACCOUNT_KEY"];
            string location = ConfigurationManager.AppSettings["LOGENTRIES_LOCATION"];

            if (!string.IsNullOrWhiteSpace(key) && !string.IsNullOrWhiteSpace(location))
            {
                var loggingConfiguration = new LoggingConfiguration();

                var logEntiresTarget = new LogentriesTarget();
                logEntiresTarget.Key = key;
                logEntiresTarget.Location = location;
                logEntiresTarget.Debug = true;
                logEntiresTarget.Layout = "${date:format=u} ${logger} ${level} ${message} ${exception:format=tostring}";
                loggingConfiguration.AddTarget("logentries", logEntiresTarget);

                var loggingRule = new LoggingRule("*", LogLevel.Debug, logEntiresTarget);
                loggingConfiguration.LoggingRules.Add(loggingRule);

                LogManager.Configuration = loggingConfiguration;
            }
        }
Пример #2
0
        /// <summary>
        /// Adds TextWriterTraceListener logging to the logging listeners. The text files are written to
        /// the App_Data/Logs file as roadkill.txt and are not rolling logs.
        /// </summary>
        public static void UseLogEntriesLogging()
        {
            // See https://logentries.com/doc/dotnet/
            LogentriesTarget target = new LogentriesTarget();
            target.Key = ConfigurationManager.AppSettings["LOGENTRIES_ACCOUNT_KEY"];
            target.Location = ConfigurationManager.AppSettings["LOGENTRIES_LOCATION"];
            target.Token = ConfigurationManager.AppSettings["LOGENTRIES_TOKEN"];
            target.HttpPut = false;
            target.Ssl = false;
            target.Debug = true;

            AddNLogTarget(target, "RoadkillLogEntries");
        }