Question

Now I've a web application and 3 background application in AppHarbor . I want to use logentries to log each app in different location. based on logentries docs for AppHarbor https://logentries.com/doc/appharbor/ the token keys are read from web.config and app.config [configuration vars] enforced by appharbor.

How can I configure each application to log in different log location (eg. Appharbor/Website, AppHarbor/Console1, AppHarbor/Console2)?

Was it helpful?

Solution

You can override the config vars injected by AppHarbor by specifying the Token in the appender/target definition. Not sure which framework you're using but if its NLog then where you have this line in your web/app.config

<target name="logentries" type="Logentries" debug="true" layout="${date:format=ddd MMM dd} ${time:format=HH:mm:ss} ${date:format=zzz yyyy} ${logger} : ${LEVEL}, ${message}"/>

Add token="abc" so that you have this:

<target name="logentries" type="Logentries" debug="true" token="abc" layout="${date:format=ddd MMM dd} ${time:format=HH:mm:ss} ${date:format=zzz yyyy} ${logger} : ${LEVEL}, ${message}"/>

And then if you're using the log4net plugin, where you have this section:

<appender name="LeAppender" type="log4net.Appender.LogentriesAppender, LogentriesLog4net"> <Debug value="true" /> <layout type="log4net.Layout.PatternLayout"> <param name="ConversionPattern" value="%d{ddd MMM dd HH:mm:ss zzz yyyy} %logger %: %level%, %m" /> </layout> </appender>

Add so that you have this:

<appender name="LeAppender" type="log4net.Appender.LogentriesAppender, LogentriesLog4net"> <Debug value="true" /> <Token value="abc" /> <layout type="log4net.Layout.PatternLayout"> <param name="ConversionPattern" value="%d{ddd MMM dd HH:mm:ss zzz yyyy} %logger %: %level%, %m" /> </layout> </appender>

Token values set here will take precedence over those injected by Appharbor, so for each app that has its own web/app.config you can enter your own token using this method.

OTHER TIPS

I Found that I can set the token in runtime by below lines :

private static readonly ILog log = log4net.LogManager.GetLogger(typeof(Program));

appender = (LogentriesAppender)log.Logger.Repository.GetAppenders()[0];
appender.Token = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";

//now log method will use my token 
log.Info("Hello World");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top