Where Asp.Net Core stored log file that ILogger write ?
Is it any standard way to change log files location ?
I don't want to use any pacakges like https://www.nuget.org/packages/serilog.extensions.logging.file
Where Asp.Net Core stored log file that ILogger write ?
Is it any standard way to change log files location ?
I don't want to use any pacakges like https://www.nuget.org/packages/serilog.extensions.logging.file
Built-in logging providers for ASP.NET Core applications are:
None of these classes can be used for logging to the file by default.
However, you can use tracing listener, which can be set up for file usage, like this:
public void Configure(IApplicationBuilder app,
IHostingEnvironment env,
ILoggerFactory loggerFactory)
{
loggerFactory
.AddDebug();
// add Trace Source logging
var testSwitch = new SourceSwitch("sourceSwitch", "Logging Sample");
testSwitch.Level = SourceLevels.Warning;
loggerFactory.AddTraceSource(testSwitch,
new TextWriterTraceListener("MyLogName.txt"));
As you can see, here you can filter your messages, right now it will write down all the warnings and higher messages. Also you can setup a filter for listener:
var testSwitch = new SourceSwitch("sourceSwitch", "Logging Sample");
var listener = new TextWriterTraceListener("MyLogName.txt");
listener.Filter = new SourceFilter("YourFilterName");
loggerFactory.AddTraceSource(testSwitch, listener);
In consumer classes this can be used as:
logger = loggerFactory.CreateLogger("YourFilterName");
Related articles:
ILoggermethod are you calling?