I'd like to log some special events into a different table that will contain more data then the general application log.
If I add a second database target to the NLog.config
how can I use it in my code?
Would this be the right thing to do:
NLog
.LogManager
.Configuration
.AllTargets
.Single(x => x.Name == "mySecondLogTable")
.WriteAsyncLogEvent(...);
Then in the NLog.config
I would just skip this target in the rules element, right?
Summary: I'd like to define multiple database targets like a general log and specialized log for cases where I need to log more details into a different table. I'd like to use the general log by default and the special log only in functions that need this special kind of logging because of their business logic.
You always can create another logger instance where you want with specified name of target. What is the problem?
For example I want to make an extended logging into a separate file. Than I go and create
<rules>
<logger name="ExtendedLogging" minlevel="Trace" writeTo="extendedLogging"/>
</rules>
<targets>
<target name="extendedLogging" >
<target xsi:type="File" fileName="C:/Logs/ExtendedLog${shortdate}.log" createDirs="true" />
</target>
</targets>
Then go to your code and create
private readonly Logger logger = LogManager.GetLogger("ExtendedLogging");
I don't think it's a good idea to search for something inside the config-file and perform logging through something like a backdoor. It's better to make all this things explicitly.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments