How do I configure my ILogger
to write to a different location? I would like to write my logs to C:\Logs\MyLogFile.log
.
I am setting my custom LoggerFactory
like so:
app.Properties["server.LoggerFactory"] = new MyCustomLoggerFactory();
MyCustomLoggerFactory
looks like this:
public class MyCustomLoggerFactory: ILoggerFactory
{
public ILogger Create(string name)
{
return new CustomLogger();
}
}
Then ICustomLogger
interface and CustomLogger
class look like this:
public interface ICustomLogger : ILogger
{
}
public class CustomLogger : ICustomLogger
{
public bool WriteCore(TraceEventType eventType, int eventId, object state,
Exception exception, Func<object, Exception, string> formatter)
{
throw new NotImplementedException("Dont use this one dummy");
}
}
Is there no way to set the LogLevel or Url where the log file gets written? Ideally I would like to also use log4net for this.
You can make a log4net implementation for in your custom logger, you have to use the TraceEventType to determine the logging level:
public class CustomLogger : ICustomLogger
{
public bool WriteCore(TraceEventType eventType, int eventId, object state,
Exception exception, Func<object, Exception, string> formatter)
{
ILog logger = LogManager.GetLogger("myowinlogger");
switch (eventType){
case(TraceEventType.Critical):
{
logger.Fatal(...);
}
....
}
}
Make sure you have a configure and you can make a log4net configuration to write to a specific location or appender.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With