Exemplo n.º 1
0
        private LoggingConfiguration CreateNLogConfig()
        {
            var cfg = new LoggingConfiguration();
            var trg = new FileTarget()
            {
                FileName = "${basedir}/logs/${longdate}.log",
                Layout   = "[${time}]   ${message}  ${exception}",
            };

            cfg.AddRule(LogLevel.Trace, LogLevel.Fatal, trg);
            return(cfg);
        }
Exemplo n.º 2
0
        public static void Main(string[] args)
        {
            Console.Title = "AivyCore - 1.0.0";

            configuration.AddRule(LogLevel.Debug, LogLevel.Fatal, log_console);
            LogManager.Configuration = configuration;

            DofusServer  server   = new DofusServer(@"C:\Users\ABCD\AppData\Local\Ankama\zaap\retro\resources\app\retroclient");
            ServerEntity s_entity = server.Active(true, 777);

            Console.ReadLine();
        }
Exemplo n.º 3
0
    private static void LogConfiguration()
    {
        var config = new LoggingConfiguration()

                     // Targets where to log to: File and Console
                     var f1 = new FileTarget("file1")
        {
            FileName = "file1.txt"
        };
        var f2 = new FileTarget("file2")
        {
            FileName = "file2.txt"
        };

        // Rules for mapping loggers to targets
        config.AddRule(LogLevel.Info, LogLevel.Fatal, f1);
        config.AddRule(LogLevel.Debug, LogLevel.Fatal, f2);

        // Apply config
        NLog.LogManager.Configuration = config;
    }
Exemplo n.º 4
0
        private static void ConfigureNLog()
        {
            LoggingConfiguration logConfig = new LoggingConfiguration();

            FileTarget logfile = new FileTarget("logfile")
            {
                FileName = "app.log",
                Layout   = @"${date:format=HH\:mm\:ss} ${logger:long=True} ${level}: ${message} ${exception}",
                Encoding = Encoding.UTF8
            };

            ConsoleTarget logconsole = new ConsoleTarget("logconsole")
            {
                Layout = @"${date:format=HH\:mm\:ss} ${logger:long=True} ${level}: ${message} ${exception}",
            };

            logConfig.AddRule(LogLevel.Info, LogLevel.Fatal, logconsole);
            logConfig.AddRule(LogLevel.Debug, LogLevel.Fatal, logfile);

            LogManager.Configuration = logConfig;
        }
Exemplo n.º 5
0
        public static void LoadNormalConfig(LoggingConfiguration config)
        {
            ColoredConsoleTarget consoleTarget = new ColoredConsoleTarget
            {
                Name   = "console",
                Layout = "[x] ${message}"
            };

            config.AddRule(LogLevel.Error, LogLevel.Fatal, consoleTarget, "*");
            SetConsoleColor(consoleTarget);
            LogManager.Configuration = config;
        }
        public NLogLog4TcOutputTest()
        {
            _output = new NLogLog4TcOutput(new NLogLog4TcOutputConfiguration());

            var config = new LoggingConfiguration();

            config.AddTarget("target", _target);

            config.AddRule(NLogLevel.Trace, NLogLevel.Fatal, "target");

            LogManager.Configuration = config;
        }
Exemplo n.º 7
0
        static Base()
        {
            var config        = new LoggingConfiguration();
            var consoleTarget = new ColoredConsoleTarget
            {
                Layout = @"${date:format=| yyyy-MM-dd HH\:mm\:ss} | ${pad:padding=5:inner=${level}} | ${message}"
            };

            config.AddTarget("console", consoleTarget);
            config.AddRule(LogLevel.Trace, LogLevel.Fatal, consoleTarget);
            LogManager.Configuration = config;
        }
Exemplo n.º 8
0
        public static LoggingConfiguration ConfigureNLog()
        {
            var loggingConfig = new LoggingConfiguration();

            // Targets where to log to: File and Console
            var logfile = new FileTarget("logfile")
            {
                FileName          = "../../../../logs/BuyEngine.WebApi/log.txt",
                ArchiveFileName   = "log-{#}.txt",
                ArchiveNumbering  = ArchiveNumberingMode.Date,
                ArchiveDateFormat = "yyyyMMdd-HH",
                Layout            = "${longDate}|${level:uppercase=true}|${logger}|${callsite}|${message}"
            };
            var logconsole = new ConsoleTarget("logconsole");

            // Rules for mapping loggers to targets
            loggingConfig.AddRule(LogLevel.Info, LogLevel.Fatal, logconsole);
            loggingConfig.AddRule(LogLevel.Debug, LogLevel.Fatal, logfile);

            return(loggingConfig);
        }
Exemplo n.º 9
0
    public static void AddFileOutputToLogger(LoggingConfiguration configuration, string filename = "logs/ApplicationLog.txt")
    {
        var logfile = new FileTarget(filename);

        logfile.Layout            = _localLayout;
        logfile.MaxArchiveFiles   = 30;
        logfile.ArchiveDateFormat = "yyyy-MM";
        logfile.ArchiveNumbering  = ArchiveNumberingMode.Date;
        logfile.ArchiveEvery      = FileArchivePeriod.Month;
        logfile.FileName          = filename;
        configuration.AddRule(LogLevel.Info, LogLevel.Fatal, logfile);
    }
Exemplo n.º 10
0
        private static void SetUpLogging(CommandLineOptions commandLineOptions)
        {
            var config = new LoggingConfiguration();

            if (commandLineOptions.WriteLogsToFile)
            {
                var logfile = new FileTarget("logfile")
                {
                    FileName = "run_results.log"
                };
                config.AddRule(LogLevel.Info, LogLevel.Fatal, logfile);
            }

            if (commandLineOptions.WriteLogsToConsole)
            {
                var logconsole = new ConsoleTarget("logconsole");
                config.AddRule(LogLevel.Info, LogLevel.Fatal, logconsole);
            }

            LogManager.Configuration = config;
        }
Exemplo n.º 11
0
            public LogFactory GetLoggerFactory(Action <SentryNLogOptions> customConfig = null)
            {
                var target = GetTarget(customConfig);
                var config = new LoggingConfiguration();

                config.AddTarget("sentry", target);
                config.AddRule(LogLevel.Trace, LogLevel.Fatal, target);

                var factory = new LogFactory(config);

                return(factory);
            }
Exemplo n.º 12
0
        public static void LoadDebugConfig(LoggingConfiguration config)
        {
            ColoredConsoleTarget consoleTarget = new ColoredConsoleTarget
            {
                Name   = "console",
                Layout = "[!] ${level:uppercase=true} (${callsite}): ${message}"
            };

            config.AddRule(LogLevel.Debug, LogLevel.Fatal, consoleTarget, "*");
            SetConsoleColor(consoleTarget);
            LogManager.Configuration = config;
        }
Exemplo n.º 13
0
        private static void ConfigureLoggingFromCode()
        {
            var config        = new LoggingConfiguration();
            var consoleTarget = new ConsoleTarget
            {
                Name   = "console",
                Layout = "${longdate}|${level:lowercase=true}|${logger}|${message}",
            };

            config.AddRule(LogLevel.Debug, LogLevel.Fatal, consoleTarget, "*");
            LogManager.Configuration = config;
        }
Exemplo n.º 14
0
        static Lumberjack()
        {
            var config = new LoggingConfiguration();

            var format = "[${longdate}] [${threadname}/${level:uppercase=true}] [${logger}] ${message}";
            var layout = new SimpleLayout(format);

            var logfile = new FileTarget("logfile")
            {
                FileName = "output.log", Layout = layout
            };
            var logconsole = new ConsoleTarget("logconsole")
            {
                Layout = layout
            };

            config.AddRule(LogLevel.Debug, LogLevel.Fatal, logconsole);
            config.AddRule(LogLevel.Debug, LogLevel.Fatal, logfile);

            LogManager.Configuration = config;
        }
Exemplo n.º 15
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Home form = new Home();

            LoggingConfiguration config = new LoggingConfiguration();

            config.AddRule(LogLevel.Trace, LogLevel.Fatal, new TextBoxTarget(form.LogTextBox)
            {
                Layout = "[${date}] [${level}] ${message}"
            });
            config.AddRule(LogLevel.Trace, LogLevel.Fatal, new ToolStripStatusLabelTarget(form.LogToolStripStatusLabel)
            {
                Layout = "${message}"
            });
            LogManager.Configuration = config;

            Application.Run(form);
        }
Exemplo n.º 16
0
        internal static void InitDebug()
        {
            // Make sure crash dir is available for logs as early as possible
            string logPath = DirectoryUtil.RegisterDirectory("logs");

            // Init the Logger
            _logConfiguration = new LoggingConfiguration();

            string headerLayout = $"Blish HUD v{Program.OverlayVersion}";

            var logFile = new FileTarget("logfile")
            {
                Layout            = $"{STRUCLOG_TIME} | {STRUCLOG_LEVEL} | {STRUCLOG_LOGGER} | {STRUCLOG_MESSAGE}{STRUCLOG_EXCEPTION}",
                Header            = headerLayout,
                FileNameKind      = FilePathKind.Absolute,
                ArchiveFileKind   = FilePathKind.Absolute,
                FileName          = Path.Combine(logPath, "blishhud.${cached:${date:format=yyyyMMdd-HHmmss}}.log"),
                ArchiveFileName   = Path.Combine(logPath, "blishhud.${cached:${date:format=yyyyMMdd-HHmmss}}.{#}.log"),
                ArchiveDateFormat = "yyyyMMdd-HHmmss",
                ArchiveAboveSize  = MAX_LOG_SIZE,
                ArchiveNumbering  = ArchiveNumberingMode.Sequence,
                MaxArchiveFiles   = MAX_LOG_SESSIONS,
                EnableFileDelete  = true,
                CreateDirs        = true,
                Encoding          = Encoding.UTF8,
                KeepFileOpen      = true
            };

            var asyncLogFile = new AsyncTargetWrapper("asynclogfile", logFile)
            {
                QueueLimit        = 200,
                OverflowAction    = AsyncTargetWrapperOverflowAction.Discard,
                ForceLockingQueue = false
            };

            _logConfiguration.AddTarget(asyncLogFile);

            _logConfiguration.AddRule(
                ApplicationSettings.Instance.DebugEnabled
                                          ? LogLevel.Debug
                                          : LogLevel.Info,
                LogLevel.Fatal, asyncLogFile
                );

            if (ApplicationSettings.Instance.DebugEnabled)
            {
                AddDebugTarget(_logConfiguration);
            }

            LogManager.Configuration = _logConfiguration;

            Logger = Logger.GetLogger <DebugService>();
        }
Exemplo n.º 17
0
        private Logger()
        {
            try
            {
                var assembly  = Assembly.GetCallingAssembly();
                var name      = assembly.GetName().Name;
                var directory = Path.GetDirectoryName(assembly.CodeBase.Replace(@"file:///", string.Empty));

                if (!Directory.Exists(directory))
                {
                    throw new DirectoryNotFoundException(directory);
                }

                var logDirectory = Path.Combine(directory, "Logs/");

                var config = new LoggingConfiguration();

                var allFileTarget = new FileTarget("allFileTarget")
                {
                    FileName         = logDirectory + "Debug.log",
                    Layout           = "${longdate} ${uppercase:${level}} ${message}",
                    Encoding         = Encoding.Unicode,
                    ArchiveFileName  = logDirectory + "Debug.${shortdate}.{#}.log",
                    ArchiveAboveSize = 16_777_216,
                    ArchiveEvery     = FileArchivePeriod.Day,
                    ArchiveNumbering = ArchiveNumberingMode.Rolling,
                    MaxArchiveFiles  = 20
                };
                var errorFileTarget = new FileTarget("errorFileTarget")
                {
                    FileName         = logDirectory + "Error.log",
                    Layout           = "${longdate} ${uppercase:${level}} ${message}",
                    Encoding         = Encoding.Unicode,
                    ArchiveFileName  = logDirectory + "Error.${shortdate}.{#}.log",
                    ArchiveAboveSize = 16_777_216,
                    ArchiveEvery     = FileArchivePeriod.Day,
                    ArchiveNumbering = ArchiveNumberingMode.Rolling,
                    MaxArchiveFiles  = 20
                };
                config.AddTarget(allFileTarget);
                config.AddTarget(errorFileTarget);

                config.AddRuleForAllLevels(allFileTarget);
                config.AddRule(LogLevel.Error, LogLevel.Fatal, errorFileTarget);

                LogManager.Configuration = config;
                _logger = LogManager.GetLogger($"{name}.Logger");
            }
            catch (Exception exception)
            {
                MessageBox.Show($"{exception.Message}\n{exception.StackTrace}");
            }
        }
        private static void ConfigureLogging(Options options)
        {
            var config        = new LoggingConfiguration();
            var consoleTarget = new ColoredConsoleTarget("Console")
            {
                Layout = @"${date:format=HH\:mm\:ss} ${level} ${message} ${exception}"
            };

            config.AddTarget(consoleTarget);
            config.AddRule(options.Verbose ? LogLevel.Debug : LogLevel.Info, LogLevel.Fatal, consoleTarget.Name);
            LogManager.Configuration = config;
        }
Exemplo n.º 19
0
        public NLogLogger(string directory)
        {
            logger = LogManager.GetLogger(LoggerName);
            var config  = new LoggingConfiguration();
            var logfile = new FileTarget("logfile")
            {
                FileName = directory
            };

            config.AddRule(LogLevel.Debug, LogLevel.Fatal, logfile);
            LogManager.Configuration = config;
        }
Exemplo n.º 20
0
        public static void Configurate()
        {
            var config  = new LoggingConfiguration();
            var logfile = new FileTarget("logfile")
            {
                FileName = "file.txt"
            };

            config.AddRule(LogLevel.Debug, LogLevel.Fatal, logfile);
            LogManager.Configuration = config;
            LogManager.GetCurrentClassLogger();
        }
Exemplo n.º 21
0
        internal static void Initialize()
        {
            string appDataLocal = $"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}\\CoCo";

            if (!Directory.Exists(appDataLocal))
            {
                Directory.CreateDirectory(appDataLocal);
            }

            FileTarget fileTarget      = new FileTarget("File");
            FileTarget fileDebugTarget = new FileTarget("File debug");

            const string format = "${logger}:_${date}:_${level}:_${message}";

            fileTarget.Layout   = format;
            fileTarget.FileName = $"{appDataLocal}\\file.log";

            fileDebugTarget.Layout   = $"{format}${{newline}}${{stacktrace}}";
            fileDebugTarget.FileName = $"{appDataLocal}\\file_debug.log";

            BufferingTargetWrapper bufferWrapper = new BufferingTargetWrapper
            {
                WrappedTarget       = fileTarget,
                BufferSize          = 300,
                FlushTimeout        = 10,
                Name                = "Buffered file",
                OptimizeBufferReuse = true
            };

            LoggingConfiguration config = new LoggingConfiguration();

            config.AddTarget(bufferWrapper);
            config.AddTarget(fileDebugTarget);
            config.AddRule(LogLevel.Debug, LogLevel.Debug, fileDebugTarget, "*");
            config.AddRule(LogLevel.Info, LogLevel.Fatal, bufferWrapper, "*");

            //LogManager.ThrowConfigExceptions = true;
            //LogManager.ThrowExceptions = true;
            LogManager.Configuration = config;
        }
Exemplo n.º 22
0
        static void ConfigureNlog()
        {
            var assemblyVersion = typeof(App)
                                  .Assembly
                                  .GetCustomAttribute <AssemblyInformationalVersionAttribute>()?
                                  .InformationalVersion ?? "0.0.0";

            var layout = $"${{date}} Process id: ${{processid}}, Version: ${{assembly-version:${assemblyVersion}}}, Thread: ${{threadname}}, ${{logger}} - ${{message}} " +
                         "${onexception:EXCEPTION OCCURRED\\:${exception:format=ToString,StackTrace}}";

            var config = new LoggingConfiguration();

            var fileTarget = new FileTarget("logfile")
            {
                FileName = "demoapp.log",
                Layout   = layout
            };

            config.AddRule(LogLevel.Trace, LogLevel.Fatal, fileTarget);

            var consoleTarget = new ConsoleTarget("logconsole")
            {
                Layout = layout
            };

            config.AddRule(LogLevel.Trace, LogLevel.Fatal, consoleTarget);

            if (Debugger.IsAttached)
            {
                var debugTarget = new DebuggerTarget("debug")
                {
                    Layout = layout
                };
                config.AddRule(LogLevel.Trace, LogLevel.Fatal, debugTarget);
            }

            LogManager.Configuration = config;

            SetNlogLogLevel(LogLevel.Trace);
        }
Exemplo n.º 23
0
        public override CancellationTokenSource Start(HttpProfile profile)
        {
            IWebHost host = BuildWebHost(profile);

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                HttpListenerContext context = services.GetRequiredService <HttpListenerContext>();
                context.Database.EnsureCreated();
                if (!context.Listener.Any())
                {
                    context.Listener.Add(this);
                }
                context.SaveChanges();
            }
            CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
            LoggingConfiguration    loggingConfig           = new LoggingConfiguration();
            var consoleTarget = new ColoredConsoleTarget();
            var fileTarget    = new FileTarget();

            loggingConfig.AddTarget("console", consoleTarget);
            loggingConfig.AddTarget("file", fileTarget);
            consoleTarget.Layout = @"${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}";
            fileTarget.Layout    = @"${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}";
            fileTarget.FileName  = Common.CovenantLogDirectory + "covenant-http.log";
            loggingConfig.AddRule(NLog.LogLevel.Warn, NLog.LogLevel.Fatal, "console");
            loggingConfig.AddRule(NLog.LogLevel.Warn, NLog.LogLevel.Fatal, "file");

            var logger = NLogBuilder.ConfigureNLog(loggingConfig).GetCurrentClassLogger();

            System.Threading.Tasks.Task task = host.RunAsync(cancellationTokenSource.Token);
            // Don't love this, but we wait to see if the Listener throws an error on Startup
            Thread.Sleep(100);
            if (task.Status != System.Threading.Tasks.TaskStatus.Faulted)
            {
                this.Status = ListenerStatus.Active;
                return(cancellationTokenSource);
            }
            return(null);
        }
Exemplo n.º 24
0
        /// <summary>
        /// Runs this console app
        /// </summary>
        public void Run()
        {
            // Setup NLog
            var config = new LoggingConfiguration();

            // Targets where to log to: Console
            var logConsole = new ConsoleTarget("logConsole");

            // Rules for mapping loggers to targets
            config.AddRule(LogLevel.Trace, LogLevel.Fatal, logConsole);

            // Apply config
            LogManager.Configuration = config;

            this.PrintSeparator();
            Console.WriteLine("Welcome to CDP4 SDK sample app!");
            this.PrintSeparator();

            Console.WriteLine("Enter your user name (default is admin, just press Enter):");
            var userName = string.IsNullOrWhiteSpace(Console.ReadLine()) ? "admin" : Console.ReadLine();

            Console.WriteLine("Enter your password (to use default just press Enter):");
            var pass = string.IsNullOrWhiteSpace(Console.ReadLine()) ? "pass" : Console.ReadLine();

            Console.WriteLine(
                "Enter a server's URL for future requests (default is https://cdp4services-test.cdp4.org, just press Enter):");
            this.uri = new Uri(string.IsNullOrWhiteSpace(Console.ReadLine())
                ? "https://cdp4services-test.cdp4.org"
                : Console.ReadLine());

            var dal = new CdpServicesDal();

            this.credentials = new Credentials(userName, pass, this.uri);
            this.session     = new Session(dal, this.credentials);

            this.PrintCommands();

            while (this.isRunning)
            {
                try
                {
                    this.ExecuteCommand(Console.ReadLine());
                }
                catch (Exception ex)
                {
                    this.PrintSeparator();
                    Console.WriteLine("Something went wrong. Sorry about that.");
                    Console.WriteLine(ex.Message);
                    this.PrintSeparator();
                }
            }
        }
Exemplo n.º 25
0
        public static void ClassInitialize(TestContext context)
        {
            var config        = new LoggingConfiguration();
            var consoleTarget = new ConsoleTarget
            {
                Name   = "console",
                Layout = "${longdate}|${level:uppercase=true}|${logger}|${message}",
            };

            config.AddRule(LogLevel.Trace, LogLevel.Fatal, consoleTarget, "*");

            LogManager.Configuration = config;
        }
Exemplo n.º 26
0
        private static Logger CreateLogger()
        {
            LoggingConfiguration configuration = new LoggingConfiguration();
            FileTarget           fileTarget    = new FileTarget("log")
            {
                FileName = Log.LogPath
            };

            //fileTarget.DeleteOldFileOnStartup = true;
            configuration.AddRule(LogLevel.Info, LogLevel.Fatal, fileTarget);
            LogManager.Configuration = configuration;
            return(LogManager.GetCurrentClassLogger());
        }
        private static void AddLocalTarget(LoggingConfiguration config, string appName)
        {
            InternalLogger.LogFile = Path.Combine(Directory.GetCurrentDirectory(), $"logs\\nlog-internal.{appName}.log");
            var fileTarget = new FileTarget("Disk")
            {
                FileName = Path.Combine(Directory.GetCurrentDirectory(), $"logs\\{appName}.${{shortdate}}.log"),
                Layout   = "${longdate} [${uppercase:${level}}] [${logger}] - ${message} ${onexception:${exception:format=tostring}}"
            };

            config.AddTarget(fileTarget);

            config.AddRule(GetMinLogLevel(), LogLevel.Fatal, "Disk");
        }
Exemplo n.º 28
0
        static Log()
        {
            CurrentLogDirectory = Path.Combine(DataLocation.DataDirectory(), DirectoryName, Constant.Version);
            if (!Directory.Exists(CurrentLogDirectory))
            {
                Directory.CreateDirectory(CurrentLogDirectory);
            }

            var configuration = new LoggingConfiguration();
            var fileTarget    = new FileTarget()
            {
                FileName = CurrentLogDirectory.Replace(@"\", "/") + "/${shortdate}.txt",
            };
            var consoleTarget = new NLog.Targets.ConsoleTarget();

#if DEBUG
            configuration.AddRule(LogLevel.Debug, LogLevel.Fatal, fileTarget);
#else
            configuration.AddRule(LogLevel.Info, LogLevel.Fatal, fileTarget);
#endif
            LogManager.Configuration = configuration;
        }
Exemplo n.º 29
0
        public static LoggingConfiguration getNewConfig()
        {
            var config = new LoggingConfiguration();

            // Targets where to log to: File and Console
            var logfile = new NLog.Targets.FileTarget("file")
            {
                FileName = "${basedir}/Logs/${shortdate}.${level}.log",
                Layout   = "${longdate} ${logger} ${message}${exception:format=ToString}"
            };

            var logconsole = new NLog.Targets.ConsoleTarget("console")
            {
                Layout = "${date}|${level:uppercase=true}|${message} ${exception} ${all-event-properties}"
            };

            // Rules for mapping loggers to targets
            config.AddRule(LogLevel.Debug, LogLevel.Fatal, logconsole);
            config.AddRule(LogLevel.Debug, LogLevel.Fatal, logfile);

            return(config);
        }
Exemplo n.º 30
0
            public LogFactory GetLoggerFactory(bool asyncTarget = false)
            {
                var target = GetTarget(asyncTarget);

                var config = new LoggingConfiguration();

                config.AddTarget("sentry", target);
                config.AddRule(LogLevel.Trace, LogLevel.Fatal, target);

                var factory = new LogFactory(config);

                return(factory);
            }
Exemplo n.º 31
0
        public void SetUp()
        {
            var cfg = new LoggingConfiguration();

            _logTarget = new MemoryTarget("mem")
            {
                Layout = new SimpleLayout("${Logger}|${Level}|${Message}|${exception}|${all-event-properties}")
            };

            cfg.AddTarget(_logTarget);

            cfg.AddRule(global::NLog.LogLevel.Trace, global::NLog.LogLevel.Error, _logTarget);

            LogManager.Configuration = cfg;
        }