Logging With NLog In Azure WebJobs -


i've got nlog configuration works fine web app (asp.net core). i'm trying add nlog webjobs, can't figure out how it.

in program.cs within webjob project, need somehow inject ihostingenvironment , iloggerfactory (both of inject startup constructor of web app). once know how that, should able finish off configuration.

if that's not possible, alternatives have?

i'm not keen use textwriter class passed webjob methods, imagine difficult extract logs , route them want go.

following steps of using nlog in webjob.

step 1, install nlog.config package webjob.

install-package nlog.config 

step 2, add rules , targets nlog.config files. following sample of writing logs file.

<?xml version="1.0" encoding="utf-8" ?> <nlog xmlns="http://www.nlog-project.org/schemas/nlog.xsd"       xmlns:xsi="http://www.w3.org/2001/xmlschema-instance">   <targets>     <target name="logfile" xsi:type="file" filename="file.txt" />   </targets>   <rules>     <logger name="*" minlevel="info" writeto="logfile" />   </rules> </nlog> 

step 3, logger instance using logmanager class.

private static logger logger = logmanager.getlogger("mylog"); 

step 4, after got logger instance, write log using following code.

logger.trace("sample trace message"); logger.debug("sample debug message"); 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -