Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use it on .Net 6? #96

Open
somunich opened this issue Nov 1, 2022 · 1 comment
Open

How to use it on .Net 6? #96

somunich opened this issue Nov 1, 2022 · 1 comment

Comments

@somunich
Copy link

somunich commented Nov 1, 2022

Hello, do you have an example on how to configure this package to work with .Net 6?
I have the configuration file, but I can't see any log on kibana.

in program.cs I have
XmlConfigurator.Configure(new FileInfo("log4net.config"));

But what to do in order to get log4stash working?

@danammeansbear
Copy link

Before using Log4Stash in your personal project, you want to create a console program to test your server with assuming everything works in postman. Tho postman could just be using curl....

but below should allow you to test if your system is working. you will need to modify your config correct. if you can log files to a local folder without issues then it might be a network issue.

`
using System;
using log4net;
using log4net.Config;
using System.IO;
using System.Reflection;

[assembly: XmlConfigurator(ConfigFile = "log4net.config", Watch = true)]

namespace ELKTest
{
internal class Program
{
private static readonly ILog logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

    static void Main(string[] args)
    {
        // Enable log4net internal debugging
        log4net.Util.LogLog.InternalDebugging = true;
        log4net.Config.XmlConfigurator.Configure();

        var logger = LogManager.GetLogger("elk_test");

        try
        {
            // Ensure log4net is configured
            var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());
            //XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));
            //log4net.Config.XmlConfigurator.Configure();

            //var logger = LogManager.GetLogger("console_test_logger");
            logger.Debug("This is a DEBUG message.");
            logger.Info("This is an INFO message.");
            logger.Warn("This is a WARN message.");
            logger.Error("This is an ERROR message.");

            Console.WriteLine("Log messages have been sent to Elasticsearch.");
        }
        catch (Exception ex)
        {
            Console.WriteLine("Error occurred: " + ex.Message);
        }
    }
}

}

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants