Sentinel configuration with NLog/log4net - log4net

I have just started to use logging for my C# application. I am using NLog for logging entries to a *.log file and I view it using a Notepad++.
I want to try Sentinel, although I can view the logs on sentinel, I am not sure with the initial steps of sentinel, do I have to do the following every time I want to start sentinel to read a log?
Add new logger
Provider registration - NLog viewer
Visualizing the log
Cant I just start the sentinel and choose from a set configuration files ? If I am running two C# applications one using Log4Net and another Nlog, do I have to go through these over again instead of just selecting a config file?
Also what is the purpose of saving a session in sentinel ?

Once you have a session saved in a file - file.sntl - you can instruct Sentinel to pull that session in on startup by supplying the filename on the command line. I have nlog.sntl saved and use the following from a command script:
#echo off
start /B c:\apps\sentinel\sentinel nlog.sntl
I'm sure you'd be able to create a program shortcut with the same information - I just can't be bothered

Related

Mask Database URL in log file

I have a scenario where Jenkins runs Flyway(DB migration tool, similar to liquibase) commands to connect to database and execute the SQL.
The log that gets generated contains the JDBC url string.
This has been masked in Jenkins console output.
But we also redirect the log to a file(to be sent as mail attachment) in which the URL is not masked which is a risk.
Is there any way the masking can be achieved inside the log file?
Or any way to not print or skip JDBC URL string?
PS: We also use logback framework for flyway logging.
Currently the URL is printed in INFO mode. We do not want to turn INFO mode off, because it has other necessary information.
Actually once the log file gets generated,
I just run sed command to replace the string in the file.
After which the log file is sent as an attachment.
And if you're wondering how to do it on a windows machine, you could use powershell or SED command will be available in cmd if git is installed with below setting,

Where can I see the nodejs logs after I deployed on Google App Engine?

I deployed a nodejs app on Google App engine following this tutorial https://github.com/GoogleCloudPlatform/appengine-nodejs-quickstart it was successful and now I want to check the logs of the nodejs server, like in development from the terminal console. The Vms are managed by google but even if I ssh to them I don't know where to look for the logs.
You can read the stdout of the docker container that your app runs by doing docker logs <container id> in the VM instance. You can get the container id from docker ps.
No need to SSH into the instance though. You can simply fetch the logs from the Developers Console under Monitoring > Logs.
As #tamberg mentioned in a comment, the easiest option I've found for looking at logs produced by Google App Engine instances running Node.js is to simply use the log viewer at:
https://console.cloud.google.com/logs/viewer?resource=gae_app
Detailed instructions from https://cloud.google.com/appengine/docs/standard/nodejs/building-app/viewing-service-logs are as follows:
Open the Logs Viewer in the GCP Console: https://console.cloud.google.com/logs/viewer?resource=gae_app
In the first filter dropdown at the top of the page, ensure GAE Application is selected, and choose Default Service.
Use the second filter dropdown to select only stdout and click OK. This limits the viewer to logs sent to standard output.
Use the text field above the dropdowns to search for the name you used when you submitted your form. You should see the logs corresponding to your submissions.
The default logging is really awful. None of my console.log messages show up! There are a few ways you can fix this.
1) Write logs to a log file.
For example, /var/log/app_engine/custom_logs/applogs.log
https://cloud.google.com/appengine/articles/logging
"Cloud Logging and Managed VMs apps Applications using App Engine
Managed VMs should write custom log files to the VM's log directory at
/var/log/app_engine/custom_logs. These files are automatically
collected and made available in the Logs Viewer. Custom log files
must have the suffix .log or .log.json. If the suffix is .log.json,
the logs must be in JSON format with one JSON object per line. If the
suffix is .log, log entries are treated as plain text."
2) Use winston with winston-gae.
Create a transport that will send the logs to appengine.
3) Use gcloud-logging module
Too verbose for my liking, but it is another option.

Create NLOG file with latest message only

Is there any way to create a log file with NLOG will just contain the latest message. Basically I don't want to append to the log and have it only contain the latest message. The goal is to create a log file out of each of hundreds of processes that are running so I can have a separate process look at those logs to verify that a process is up and running.
The File target has a property replaceFileContentsOnEachWrite - indicates whether to replace file contents on each write instead of appending log message at the end.
http://nlog-project.org/wiki/File_target#File_replaceFileContentsOnEachWrite

log4net - per user logging

Please help me with this query in using log4net.
I am using log4net in mhy we application. I am facing issues in configuring log4net to log errors at user level.
That is, If user X logs in, I like to create file name X and all error for user X should be written in X.log. Siilarly if Y user logs in the log file should be in name of Y.log and the most important point to note is, they could log in concurrently.
I tried the luck by creating log files whose name would be framed dynamically as soon as the user logs in. But issue here, if they are not using the application at the same time, the log files are creeated with correct name and writing as expected, but if both users have active sessions, log file is created only for user who FIRST logged in and error of second user has been recorded in log file that is created for FIRST user.
Please help me in this.
There has to be a better solution from this one, but you can change log4net configuration from code and even decide which config file to load - so you can do it in code, which is not as nice as editing an XML file.
so what you need to do, which is highly not recommended, is to create log4net configuration each time you call the logger static class, and do what needed based on the calling user.
again.. it doesn't feel right !
(and it will probably perform poorly).
another BETTER solution is to log everything to database (log4net supports it), with a user column, and then produce the logs from db....

selecting a log file

We have multiple log files like database log, weblog, quartzlog in our application.
Any log from files under package /app/database will go to database log.
Any log from files under package /app/offline will go to quartzlog log.
What we need now is - want to direct the log staments from one of the java file under /app/database to be outputted to quartzlog instead of database log.
How can we select a particular log file in java file?
You need to define the appropriate appender that logs in the desired file. Read this short introduction to see how you can do it.
Then in the configuration file, you can instruct all messages from a specific package to go in the selected appender:
log4j.logger.my.package = DEBUG, myFileAppender
EDIT:
I believe that in log4j only package resolution is possible - you can't use an appender per file or method. You could try to work around this by adding an extra layer on top of log4j or implementing your own appender.
For example, instead of log.debug use:
my.loggerproxy.log.debug(message);
If you only need to do it from a single method, then the above will be enough. Just instruct the logger proxy package to be logged in a different file.

Resources