public static LoggingConfiguration UsePaperTrail(this LoggingConfiguration configuration, LogConfig config)
        {
            if (!string.IsNullOrEmpty(config.Papertrail?.Server))
            {
                var syslogTarget = new SyslogTarget
                {
                    Name            = "PaperTrail",
                    MessageCreation = new MessageBuilderConfig
                    {
                        Facility = Facility.Local7,
                        Rfc5424  = new Rfc5424Config
                        {
                            AppName  = config.ApplicationName,
                            Hostname = config.HostName ?? Environment.MachineName,
                        },
                    },
                    MessageSend = new MessageTransmitterConfig
                    {
                        Protocol = ProtocolType.Tcp,
                        Tcp      = new TcpConfig
                        {
                            Server = config.Papertrail.Server,
                            Port   = config.Papertrail.Port,
                            Tls    = new TlsConfig
                            {
                                Enabled = true,
                            },
                        },
                    },
                };

                configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.FromString(config.Papertrail.LogLevel ?? "Trace"), syslogTarget));
            }
            return(configuration);
        }
示例#2
0
        private static void SetupPapertrailLogging()
        {
            try
            {
                LoggingConfiguration config     = LogManager.Configuration;
                SyslogTarget         papertrail = new SyslogTarget
                {
                    MessageCreation = { Facility = Facility.Local7 },
                    MessageSend     =
                    {
                        Protocol = ProtocolType.Tcp,
                        Tcp      = { Server = "logs7.papertrailapp.com", Port = 13236, Tls = { Enabled = true } }
                    }
                };

                config.AddTarget("papertrail", papertrail);

                papertrail.Layout = "| " + Helpers.DisplayVersion +
                                    " |${level:uppercase=true}| ${message} ${exception:format=toString,Data}";

                LoggingRule rule = new LoggingRule("*", LogLevel.Error, papertrail);
                config.LoggingRules.Add(rule);
                LogManager.Configuration = config;
            }
            catch
            {
                Logger.Error("Failed to setup logging with papertrail");
            }
        }
示例#3
0
        private static void SetupLogging(string commandLine)
        {
            ConfigurationItemFactory.Default.RegisterItemsFromAssembly(Assembly.Load("NLog.Targets.Syslog"));

            LoggingConfiguration config = LogManager.Configuration;

            SyslogTarget syslog = new SyslogTarget
            {
                MessageCreation = { Facility = Facility.Local7 },
                MessageSend     =
                {
                    Protocol = ProtocolType.Tcp,
                    Tcp      = { Server = "logs7.papertrailapp.com", Port = 13236, Tls = { Enabled = true } }
                }
            };

            config.AddTarget("syslog", syslog);

            syslog.Layout = "| " + Helpers.DisplayVersion + " |${level:uppercase=true}| ${message} ${exception:format=toString,Data}";

            LoggingRule rule = new LoggingRule("*", LogLevel.Error, syslog);

            config.LoggingRules.Add(rule);

            LogManager.Configuration = config;

            Logger.Fatal($"TV Rename {Helpers.DisplayVersion} logging started on {Environment.OSVersion}, {(Environment.Is64BitOperatingSystem ? "64 Bit OS" : "")}, {(Environment.Is64BitProcess ? "64 Bit Process" : "")} {Environment.Version} {(Environment.UserInteractive ? "Interactive" : "")} with args: {commandLine}");
            Logger.Info($"Copyright (C) {DateTime.Now.Year} TV Rename");
            Logger.Info("This program comes with ABSOLUTELY NO WARRANTY; This is free software, and you are welcome to redistribute it under certain conditions");
        }
示例#4
0
        private static void SetupSemaTextLogging()
        {
            try
            {
                LoggingConfiguration config   = LogManager.Configuration;
                SyslogTarget         sematext = new SyslogTarget
                {
                    MessageCreation =
                    {
                        Rfc5424     =
                        {
                            AppName = "0dcb3012-fa85-47c5-b6ca-cfd33609ac33"
                        }
                    },
                    MessageSend =
                    {
                        Protocol = ProtocolType.Tcp,
                        Tcp      = { Server = "logsene-syslog-receiver.sematext.com", Port = 514 }
                    }
                };

                config.AddTarget("sema", sematext);
                JsonLayout jsonLayout = new JsonLayout
                {
                    Attributes =
                    {
                        new JsonAttribute("exceptionType",        "${exception:format=Type}"),
                        new JsonAttribute("exceptionDetails",     "${exception:format=toString,Data}"),
                        new JsonAttribute("details",              "${message}"),
                        new JsonAttribute("exceptionMessage",     "${exception:format=Message}"),
                        new JsonAttribute("level",                "${level:uppercase=true}"),
                        new JsonAttribute("appVersion",           Helpers.DisplayVersion),
                        new JsonAttribute("innerException",       new JsonLayout
                        {
                            Attributes =
                            {
                                new JsonAttribute("type",         "${exception:format=:innerFormat=Type:MaxInnerExceptionLevel=1:InnerExceptionSeparator=}"),
                                new JsonAttribute("innerMessage", "${exception:format=:innerFormat=Message:MaxInnerExceptionLevel=1:InnerExceptionSeparator=}")
                            }
                        },
                                          //don't escape layout
                                          false)
                    }
                };
                sematext.Layout = jsonLayout;

                LoggingRule semaRule = new LoggingRule("*", LogLevel.Warn, sematext);
                config.LoggingRules.Add(semaRule);
                LogManager.Configuration = config;
            }
            catch
            {
                Logger.Error("Failed to setup logging with sema");
            }
        }
示例#5
0
        public static void SetSettings()
        {
            if (false)
            {
                // Enable internal logging to a file
                InternalLogger.LogFile = "internallog.log";

                // Set internal log level
                InternalLogger.LogLevel = LogLevel.Trace;
            }

            // Configuration object
            var config = new LoggingConfiguration();

            var syslogTarget = new SyslogTarget()
            {
                Name            = "sysLog",
                MessageCreation = new MessageBuilderConfig()
                {
                    Facility = NLog.Targets.Syslog.Settings.Facility.Daemons
                },
                MessageSend = new MessageTransmitterConfig()
                {
                    Protocol = ProtocolType.Tcp,
                    Tcp      = new TcpConfig()
                    {
                        Server = "logs4.papertrailapp.com",
                        Port   = 49554,
                        Tls    = new TlsConfig()
                        {
                            Enabled = true
                        }
                    }
                }
            };

            config.AddTarget(syslogTarget);
            config.AddRule(LogLevel.Debug, LogLevel.Fatal, syslogTarget);

            // FileTarget object
            var fileTarget = new FileTarget("fileLogger")
            {
                FileName         = "${basedir}/log.log",
                ArchiveAboveSize = 104857600,
                MaxArchiveFiles  = 1,
            };

            config.AddTarget(fileTarget);

            // Define rules for target
            config.AddRule(LogLevel.Debug, LogLevel.Fatal, fileTarget);

            // Activate configuration object
            LogManager.Configuration = config;
        }
        private void SetSyslogParameters(string syslogServer, int syslogPort, LogLevel minimumLogLevel)
        {
            var syslogTarget = new SyslogTarget();

            syslogTarget.Name = "syslogTarget";
            syslogTarget.MessageSend.Protocol              = ProtocolType.Udp;
            syslogTarget.MessageSend.Udp.Port              = syslogPort;
            syslogTarget.MessageSend.Udp.Server            = syslogServer;
            syslogTarget.MessageSend.Udp.ReconnectInterval = 500;
            syslogTarget.MessageCreation.Rfc             = RfcNumber.Rfc5424;
            syslogTarget.MessageCreation.Rfc5424.AppName = "Prowlarr";

            var loggingRule = new LoggingRule("*", minimumLogLevel, syslogTarget);

            LogManager.Configuration.AddTarget("syslogTarget", syslogTarget);
            LogManager.Configuration.LoggingRules.Add(loggingRule);
        }
示例#7
0
        public static void InitializeSyslogLogger(int port, bool console)
        {
            LoggingConfiguration config = new LoggingConfiguration();

            SyslogTarget st = new SyslogTarget();

            st.Port = port;
            config.AddTarget("Syslog", st);

            config.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, st));

            if (console)
            {
                ColoredConsoleTarget ct = new ColoredConsoleTarget();
                ct.Layout = "${message}";
                config.AddTarget("Console", ct);

                config.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, ct));
            }

            LogManager.Configuration = config;
        }