how to log Environment.UserName in NLog? - nlog

how to log Environment.UserName in NLog? i have an application that works both on window authentication and form authentication. So i need to log Environment.UserName in my log file.

You could use ${windows-identity}, which uses WindowsIdentity.GetCurrent(). I'm unsure if that the same as Environment.UserName
Or (NLog 4.4+ needed)
//register at start of your program, main(), app_start etc
LayoutRenderer.Register("username", (logEvent) => Environment.UserName);
usage:
${username}
More info over ${windows-identity}, see https://github.com/NLog/NLog/wiki/Windows-Identity-Layout-Renderer

NLog ver. 4.6.4 introduces ${environment-user}.
See also: https://github.com/nlog/NLog/wiki/Environment-User-Layout-Renderer

Related

ExpressJS not showing debug messages

I am using ExpressJS and would like to display internal debug messages, like here https://expressjs.com/en/guide/debugging.html.
When I am using this command in VS Code (Windows Powershell) "`set DEBUG=express:*; node ./dist/app.js" it is starting my Node/Express Server, however it does not display any debug messages. Do I have to add something to my code so it works?
"Express uses the debug module internally to log information about route matches, middleware functions that are in use, application mode, and the flow of the request-response cycle."
Do you have this package:
https://www.npmjs.com/package/debug
And there is no semicolon between the statements.
I tried the same in windows command prompt and it worked there just exchanged the semicolon for an ampersand.
set DEBUG=express:* & node ./dist/app.js

Hybris: How to create separate log4j log files in the same extension

I need to log some audit logs to a separate file than standard console logs. I tried to create custom logger with the properties added to custom extension
log4j.appender.auditLog=org.apache.log4j.FileAppender
log4j.appender.auditLog.File=/somelogsfile.log
log4j.appender.auditLog.layout=org.apache.log4j.PatternLayout
log4j.appender.auditLog.layout.ConversionPattern=%d [%24F:%t:%L] - %m%n
log4j.category.auditLogger=INFO, auditLog
log4j.additivity.auditLogger=false
Then i have initialised logger as:
Logger LOG2= Logger.getLogger("auditLogger");
LOG2.info("Test");
The logs are output to standard console logs but not to the specified File. What am I missing?
Based on the updated question, I did some extra investigation and tested it out on my own system.
Most likely, your hybris version is making use of log4j2 this means that the config should be like this:
log4j2.appender.auditLog.type=File
log4j2.appender.auditLog.name=auditLog
log4j2.appender.auditLog.fileName=${HYBRIS_LOG_DIR}/audit.log
log4j2.appender.auditLog.layout.type=PatternLayout
log4j2.appender.auditLog.layout.pattern=%d [%24F:%t:%L] - %m%n
log4j2.logger.auditLogger.name=auditLogger
log4j2.logger.auditLogger.level=info
log4j2.logger.auditLogger.appenderRefs=auditLogger
log4j2.logger.auditLogger.appenderRef.auditLogger.ref=auditLog
log4j2.logger.auditLogger.additivity=false
I've tested this out on my local system, and using Logger LOG= Logger.getLogger("auditLogger") prints the log statements to the new file

Solr Security : authentication/authorization Not recognized

I am currently working on Solr in Standalone Mode.
Since I'm a beginner on Solr I wanted to start the server with the command start -e techproducts.
The core is well uploaded but a warning message appears:
"Not all security plugins configured! authentication= disabled authorization = disabled. Solr is only as secure as you make it. Considere configuring authentication/authorization before exposing solr to users internal or external"
The problem is that I have already created my security.json, I have put it in the home directory and I have authenticated myself at the server entrance, so it's seems efficient. Why does this warning message keep appearing?
Try writing the security.json file in the proper place, so that Solr can read during startup.
Visit the Dashboard page and look for the solr.solr.home property which should look like this: -Dsolr.solr.home=/var/solr/data, then you write the file to /var/solr/data/security.json. Then restart Solr and during startup the console should show something like thi instead of the WARN:
INFO (main) [ ] o.a.s.c.CoreContainer Initializing authorization plugin: solr.RuleBasedAuthorizationPlugin
INFO (main) [ ] o.a.s.c.CoreContainer Initializing authentication plugin: solr.BasicAuthPlugin

Logging with Nlog & Rebus

I would like to implement ReBus logging with Nlog.
We have NLog running to console, file and Database (with custom fields) and different files. I mean, NLog is up & running fine.
We have installed ReBus.Nlog Nuget Package and changed our adapter configuration to Nlog().
But nothing is logged to files in spite of we have it configured with 'Trace' loglevel.
Somebody has any simple example to implement loggin with NLog in ReBus?
I have checked the tests on Rebus.Nlog github source code, but I think it is only testing explicit sent messages to logger.
Mainly I would like to log Rebus warnings and errors.
Thanks.
I have added this Logging sample project to the RebusSamples repository – the relevant part of the code is shown here:
// configure NLog
var configuration = new LoggingConfiguration
{
LoggingRules = { new LoggingRule("*", LogLevel.Debug, new ConsoleTarget("console")) }
};
LogManager.Configuration = configuration;
// configure Rebus
Configure.With(activator)
.Logging(l => l.NLog())
.Transport(t => t.UseInMemoryTransport(new InMemNetwork(), "logging"))
.Start();
As far as I can tell, this way of configuring NLog may not be the idiomatic way, since I guess most people prefer to be able to configure rules and targets with XML in their application configuration files.
Either way, NLog ends up having the static configuration applied, and then Rebus can pick that up when you call NLog() on its logging configurer.
I hope that helps :)

How can i define a Loginmodule from Glassfish asadmin?

I'm currently implementing a Glassfish realm backed by a neo4j DB, for which I've defined a Realm and a LoginModule class.
I can install the realm using the create-auth-realm asadmin command. But the realm is recognized by Glassfish only if it is associated to a LoginModule defined in the config/login.conf file.
For instance, in my case, I have to do the following:
Create the authentication realm: create-auth-realm --classname com.mycompany.security.MyRealm --property jaas-context=MyLoginModule myrealm and then
Define MyLoginModule in that config/login.conf file :
MyLoginModule {
fr.mycompany.security.MyLoginModule required;
};
I can edit the login.conf file by hand but would like to use an asadmin command to automate this step. Would you know of such an asadmin command ?
It seems that, at the moment, the Glassfish CLI does not support this.
Quote from here:
glassfish has a pretty good CLI (which is actually one of the reasons,
why I switched over from JBoss). However, there is no CLI cmd for
modifying the login.conf of an instance (i.e. add/remove an entry in a
reliable way).
I'm wondering about why the realm is not added/removed automatically
to/from the login.conf, when one creates/deletes a realm using the
create-auth-realm/delete-auth-realm command ...
I have requested for an update.

Resources