Comments (15)
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.
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.
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.
- Create a new Console application.
dotnet new console
- Edit the
Program.cs
file and replacestatic 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"));
}
- 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 thelog4net.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.
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.
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.
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.
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).
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.
It says snk not found:
And therefore I can't publish.
from microsoft.extensions.logging.log4net.aspnetcore.
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.
Thank you. Let me know your results.
from microsoft.extensions.logging.log4net.aspnetcore.
Execute the console application:
from microsoft.extensions.logging.log4net.aspnetcore.
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.
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.
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.
@KINGGUOKUN, any news on this?
from microsoft.extensions.logging.log4net.aspnetcore.
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)
- Removing old log files HOT 1
- Missing Release Notes HOT 2
- Use it in a windows service console application HOT 1
- How to add SMTPAppender HOT 1
- Logging to different Log4Net loggers with dependency injection HOT 1
- Question about name HOT 3
- Thank you for the contribution.
- Does this work with .NET or .NET Core applications? HOT 1
- .net 7 HOT 2
- Need Example Logging Facade Use Outside of ASP HOT 2
- Enable internal debugging HOT 1
- Add .NET 8 support HOT 2
- Missing copyright notice in license
- Upgrading to net8.0 throws exception on startup. HOT 1
- Initialize without a config file HOT 1
- microsoft.extensions.logging.log4net.aspnetcore is missing NuGet package README file
- .NET8.0 XML Exception Problem HOT 4
- EventId Not Showing in Logs
- Logging latest scope value
- How do I configure log4net from in memory configuration xml element? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from microsoft.extensions.logging.log4net.aspnetcore.