Comments (6)
@huorswords yes it was solved with changing the initialization thank you
from microsoft.extensions.logging.log4net.aspnetcore.
Hello @JocelyneElKhoury7 ,
Excuse me to answer you so late, but I'm very busy at my job and I don't have so much time on the last weeks.
Could you please provide a sample or some code in order to reproduce your issue?
It is difficult to me to reproduce your scenario from scratch.
Thank you.
from microsoft.extensions.logging.log4net.aspnetcore.
Hello @huorswords,
I have fixed it and now it is logging, but i got another issue now, the same line is being logged several times, it turned out that because i have to set logger.AddLog4Net() in the constructor of every class, if i don't set it the logging won't work, and when i set it the same line is logged several times(the number of times i have initiated the logger.AddLog4Net() ) can you help me plz? below is my code, note that i am using .net core windows service 2.2
class Program
{
static void Main(string[] args)
{
ILoggerFactory loggerFactory = new LoggerFactory();
ILogger<Program> logger;
logger = loggerFactory.CreateLogger<Program>();
loggerFactory.AddLog4Net();
logger.LogInformation("Program.Main");
try
{
var builder = new ConfigurationBuilder()
.SetBasePath(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location))
.AddJsonFile("appsettings.json");
var configuration = builder.Build();
StaticVariables.SqlConnStr = configuration["ReportingDbSqlCnx"];
var serviceProvider = new ServiceCollection()
.AddLogging()
.AddMemoryCache()
.AddTransient<IGeneralDA, GeneralDA>()
.AddTransient<IGeneral, General>()
.BuildServiceProvider();
serviceQuartz.StartJobs().GetAwaiter().GetResult();
using (var service1 = new ReportingService(serviceQ))
{
ServiceBase.Run(service1);
}
}
catch (Exception ex)
{
logger.LogError(ex.ToString());
}
}
}
the logs in the program class is logged once but in the other classes it is logged several times
public class Class1 : IClass1
{
private readonly IGeneral _general;
private readonly ILogger<QuartzScheduler> _logger;
public Class1(IGeneral general, ILoggerFactory loggerFactory)
{
_general = general;
loggerFactory.AddLog4Net();
_logger = loggerFactory.CreateLogger<Class1>();
}
public async Task Start()
{
try
{
_logger.LogInformation("Class1.Start.Started");
_logger.LogInformation("Class1.Start.Ended");
}
catch (Exception se)
{
_logger.LogError(se.ToString());
}
}
}
i tried this also
public Class1(IGeneral general, ILogger<Class1> logger)
{
_general = general;
_logger = logger;
}
but in this case the logger did not write in the file
from microsoft.extensions.logging.log4net.aspnetcore.
ok i fixed it for whoever faces it, i fixed it in this line
var serviceProvider = new ServiceCollection()
.AddLogging(configure => configure.AddLog4Net())
and i used this in all my classes
public Class1(IGeneral general, ILogger<Class1> logger)
{
_general = general;
_logger = logger;
}
from microsoft.extensions.logging.log4net.aspnetcore.
@JocelyneElKhoury7 I met the same problem. and you can commit a pull request...
from microsoft.extensions.logging.log4net.aspnetcore.
@JocelyneElKhoury7 thank you very much by updating the issue.
As far as I understand, your problem is solved and the root cause was an incorrect initialization, isn't it?
I'm happy to know that you already resolved it. 👍
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.