Git Product home page Git Product logo

Comments (15)

huorswords avatar huorswords commented on July 23, 2024

Hello @KINGGUOKUN ,

Thank you by opening this issue. Could you show / share some code in order to try to reproduce it on my own? I.E. log4net.config file, initialization code...

The last version was modified to use a different way to resolve the path where the application is running. Maybe this is the root cause of your problem, but in order to see what happens, I need some additional information.

Thanks. Regards.

from microsoft.extensions.logging.log4net.aspnetcore.

KINGGUOKUN avatar KINGGUOKUN commented on July 23, 2024

Hello @KINGGUOKUN ,

Thank you by opening this issue. Could you show / share some code in order to try to reproduce it on my own? I.E. log4net.config file, initialization code...

The last version was modified to use a different way to resolve the path where the application is running. Maybe this is the root cause of your problem, but in order to see what happens, I need some additional information.

Thanks. Regards.

OK,it's as follows:
My log4net.config file:

log4net initial in the Program.cs:
public static IWebHostBuilder CreateWebHostBuilder(string[] args)
{
var config = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("hostsettings.json", optional: true)
.AddJsonFile("autofac.json", optional: true)
.AddCommandLine(args)
.Build();

        return WebHost.CreateDefaultBuilder(args)
             .UseConfiguration(config)
            .ConfigureLogging((hostingContext, logging) =>
            {
                logging.AddFilter("System", LogLevel.Warning);
                logging.AddFilter("Microsoft", LogLevel.Warning);
                logging.AddDebug();
                logging.AddConsole();
                logging.AddLog4Net();
            })
            .UseStartup<Startup>();
    }

And I am using it in ExceptionFilter:
public override void OnException(ExceptionContext context)
{
Exception exception = context.Exception;
JsonResult result = null;
if (exception is BusinessException)
{
result = new JsonResult(exception.Message)
{
StatusCode = exception.HResult
};
}
else
{
result = new JsonResult("服务器处理出错")
{
StatusCode = 500
};
_logger.LogError(exception, "服务器处理出错");
}

        context.Result = result;
    }

from microsoft.extensions.logging.log4net.aspnetcore.

huorswords avatar huorswords commented on July 23, 2024

Hello again @KINGGUOKUN ,

Thank you by the details. I think that something is missing related to the log4net.config file, but... let's try something.

  1. Create a new Console application.
dotnet new console
  1. Edit the Program.cs file and replace static void Main(string[] args) content by
static void Main(string[] args)
{
    System.Console.WriteLine(System.IO.Path.Combine(AppContext.BaseDirectory, "file.config"));
    System.Console.WriteLine(System.IO.Path.Combine(Environment.CurrentDirectory, "file.config"));
}
  1. Execute it from your centOS 7. The execution result should print on screen two paths.
  • The first path is the one that now the AddLog4Net() method is using when the log4net.config file is not specified by an absolute path.
  • The second path is the one that is configured on previous versions of the nuget.

Those values should be different. And you need to be sure that the log4net.config file is located on the first path.

  • Could be something related to the issue #53 already reported?
  • Could you try to change the log4net.config file copy options from your Visual Studio and deploy it to the centOS 7 machine?

I'll wait to your answer.

Thank you.

from microsoft.extensions.logging.log4net.aspnetcore.

KINGGUOKUN avatar KINGGUOKUN commented on July 23, 2024

Unfortunately, the two path is same:
/var/projects/PathTest/file.config
/var/projects/PathTest/file.config

And my log configuration file is in the first path.

from microsoft.extensions.logging.log4net.aspnetcore.

huorswords avatar huorswords commented on July 23, 2024

And last question... I hope...

Which is your project's target framework? On your original project, not the test one.

from microsoft.extensions.logging.log4net.aspnetcore.

KINGGUOKUN avatar KINGGUOKUN commented on July 23, 2024

And last question... I hope...

Which is your project's target framework? On your original project, not the test one.

.Net core 2.2

from microsoft.extensions.logging.log4net.aspnetcore.

huorswords avatar huorswords commented on July 23, 2024

Hello @KINGGUOKUN ,

Thank you.

I have updated the available WebApi sample on branch feature/54 in order to try to "reproduce" your scenario.

I have:

  • Set up the appsettings.json to set the log level as Debug.

  • Created the published application using:

    dotnet publish -c Debug -r ubuntu.18.04-x64
  • Executed the self-contained binaries from my Ubuntu 18.04

  • Get data from the values controller using:

    curl http://localhost:5000/api/values

In my case, the application is showing the messages coming from aspnet core logging (green).

image

Can you verify what is the result of executing this sample app on your side?

Maybe it can help to isolate your problem...

Thank you again.

from microsoft.extensions.logging.log4net.aspnetcore.

KINGGUOKUN avatar KINGGUOKUN commented on July 23, 2024

It says snk not found:
image
And therefore I can't publish.

from microsoft.extensions.logging.log4net.aspnetcore.

huorswords avatar huorswords commented on July 23, 2024

Sorry @KINGGUOKUN , you are right.

Please, after clone it, on Solution Explorer select the project Microsoft.Extensions.Logging.Log4Net.AspNetCore and go to Project > Properties.

And on the Signing tab, uncheck the Sign assembly checkbox.

image

Thank you. Let me know your results.

from microsoft.extensions.logging.log4net.aspnetcore.

KINGGUOKUN avatar KINGGUOKUN commented on July 23, 2024

Execute the console application:
image
image
image

curl:
image

from microsoft.extensions.logging.log4net.aspnetcore.

huorswords avatar huorswords commented on July 23, 2024

Thank you @KINGGUOKUN.

It seems that using the sample application the log generated is the expected.

Could you review your project configuration to match the configuration on the sample application?

from microsoft.extensions.logging.log4net.aspnetcore.

KINGGUOKUN avatar KINGGUOKUN commented on July 23, 2024

Well, I'm really confused.
When I run "dotnet XXX.dll" on windows , the log file is normally created, but fails in CentOS 7.
My project file is in https://github.com/KINGGUOKUN/Account/tree/master/Account.Core/Account

from microsoft.extensions.logging.log4net.aspnetcore.

huorswords avatar huorswords commented on July 23, 2024

I'm confused too. I have tested within an Ubuntu for Windows, rather than CentOS, but works on my side... :\

https://www.dropbox.com/s/1tvs4b759koxfbq/bandicam%202018-12-31%2012-38-22-464.mp4?dl=0

from microsoft.extensions.logging.log4net.aspnetcore.

huorswords avatar huorswords commented on July 23, 2024

@KINGGUOKUN, any news on this?

from microsoft.extensions.logging.log4net.aspnetcore.

huorswords avatar huorswords commented on July 23, 2024

Closing as I cannot reproduce it properly to isolate the problem. Any clue / repro steps will be helpful on this.

from microsoft.extensions.logging.log4net.aspnetcore.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.