Custom Logging information - wixsharp

I'm new to wix#, and wanted to know if you can either have a custom log file creation or if you can inject messages into the process.
I find that the log files are not as detailed as I would like.
Thanks for the help

Yes, you can add to the log, use session.Log
session.Log("Begin MyAction Hello World");
Here is a reference as well

Related

what is alternative for AuthActions.LOAD_USER_TOKEN_FAIL in sparatcus v3.x

I am using AuthActions.LOAD_USER_TOKEN_FAIL
action for 2.0 but when I migrate to 3.3.0 I am getting error on this as this has been removed.
can you please let me know what is the alternative for this one if I have to track the HTTP error code like v2.0
thanks in advance.
If you are using the standard "credentials" authentication.
You could extend the OOTB AuthService and overirde the loginWithCredentials, keep the same logic but add some additional logic in the catch which is called if the login failed.
I you don't want to add the logic there directly you could create your own LOAD_USER_TOKEN_FAIL and dispatch it from there. Alternatively, you can use the built in Event mechanism to create a new event an observe it elsewhere in the code.

LibGit2Sharp: how to Task-Async

Hi I have begun to use the package for some very simple tasks, mainly cloning a Git-Wiki repo and subsequently pulling the changes from the server when needed.
Now I can not see any methods corresponding to the Task-Async (TAP) pattern. Also in the documentation I could not find anything concerning.
Could you please give me some direction how to wrap the LibGit2Sharp methods into a TAP construct? Link to documentation (if I missed something) or just telling me which callback to hook up to the TaskCompletionSource object would be nice.
It also doesn't really help that I am a newbie with Git, and normally I only do basic branching, merging, pushing with it.
For cloning I use:
Repository.Clone(#"https://MyName#bitbucket.org/MyRepo/MyProject.git/wiki", "repo");
For pulling I use:
using (var repo = new Repository("repo"))
{
// Credential information to fetch
LibGit2Sharp.PullOptions options = new LibGit2Sharp.PullOptions();
options.FetchOptions = new FetchOptions();
var signature = new LibGit2Sharp.Signature(new Identity("myname", "mymail#google.com"), DateTimeOffset.Now);
Commands.Pull(repo, signature, options);
}
Thanks in advance
First of all, you should never try sync over async or async over sync. See this article.
If you're thinking of using Task.Run, don't. That will just trade on thread pool thread for another with the added cost of 2 context switches.
But you should reconsider your whole approach to this. You don't need to clone the repository just to get the contents of a file. Each version of a file, has a unique URL. You can even get the URL of a file for a specific branch.

Using Serilog from within WCF

I'm using Serilog from within my website & web API all good.
Now I want to use Serilog from within WCF.
But when I new up a LoggerConfiguration and create a logger from within WCF, the logging doesn't seem to work? Eg nothing is being output to the text file.
var seriLog = new LoggerConfiguration()
.WriteTo.File(#"C:\Serilogs\myapp.txt")
.CreateLogger();
seriLog.Debug("log message");
Ultimately I want to write to Seq from within the WCF service.
What am I missing or doing wrong?
Has anyone got some working code samples of how this would be done?
Are there tricks to using the Serilog/Seq stack from within WCF?
There are a couple of things to that come to mind-
First, is the setup code here being executed only once, i.e. at application startup, so there is exactly one logger pointing to the text file? Only one instance of the logger can use the file at a time.
Next, is the process running with permission to access the file?
Last, is the file open e.g. in Notepad or another app that might have it locked?
If none of these spark any ideas, you can set up Serilog's self-log before configuring the logger:
SelfLog.Out = Console.Error;
This should get shown in the VS debugger, so if Serilog's catching and suppressing any exceptions you should see them.
If you can't run it in a debugger, try:
SelfLog.Out = File.OpenText(#"C:\loglog.txt");
Sometimes I find running the app under the debugger with "Break on all exceptions" enabled can be a quick way to get to the bottom of it, too (Ctrl-D,E -> CLR Exceptions [x] Thrown, [x] Unhandled).

Yii load system params from Database using Active Record

I am interested in loading some system params into the Yii::app()->params array from the database using a CActiveRecord extension called SiteSetting.
Unfortunately I couldn't find much advice online for this, but believe I can place a method in SiteSetting called loadSiteSettingsToAppParams and add the setting...
'onBeginRequest'=>array('SiteSetting', 'loadSiteSettingsToAppParams')
...to the config.
I would like to know if I can only add this onBeginRequest to the Yii::app() somewhere within the SiteSetting class (to keep my code modular) and whether this is a sensible approach.
Thanks in advance.
Just re-read your question now and I'd try to provide answers.
To the question "I would like to know if I can only add this onBeginRequest to the Yii::app() somewhere within the SiteSetting class (to keep my code modular)": the answer is, You're not restricted to just a Class. You could (theoretically) place it anywhere within your application and also in the config.php file.
As to whether it's a sensible approach, it depends on the time it would take to request those settings from the database and whether you're prepared to add that time to your HttpRequest response time. The onBeforeRequest is fired before every HttpRequest and if the loadSiteSettingsToAppParams method consumes lots of time, you're adding that time to your HttpRequest response time.
I'd advise that you fetch those settings once after login and then update them only when they change (the settings are updated). This way, you could place the call to loadSiteSettingsToAppParams in the UserIdentity class and call it after a successful login.
That's just how I'd go about doing this though.
Hope I helped.
The easy & nice way to accomplish this by using a comoponent like SettingComoponent and place in the components directory protected/components then pre load this component in the preload section like this preload => array('log', 'setting', ...). That's it and now you can call this component anywhere you want like Yii:app()->setting->whatever.
I hope this is answer can be useful for you.

Logging status of application to console window

I am currently refactoring an application that prints its status to the console window. At the moment I am doing something like this:
Console.Write("Print some status.....")
//some code
Console.WriteLine("Done!")
Now while this works fine, all the logic is hidden between console.writelines and I find makes it very hard to read.
I don't know if there is a better way of doing this, but I just wanted to ask and see if anyone has come up with a better/more clean way of print application status to the console.
Any ideas?
Take a look at Log4Net, it handles everything, but might be an overkill for your app, no idea. However knowing Log4Net will likely help you down the road someday so maybe this is a good chance too learn it.
I second using Log4Net. It is pretty easy to use it without invoking the difficult parts - just do the following:
In your applications Main() method, call
log4net.Config.BasicConfigurator.Configure(new log4net.Appender.ConsoleAppender());
That sets up a basic Console logger that logs all messages to stdout.
In the class that needs logging, create a new ILog like so:
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof (MyClass));
Then in the method that needs logging, call
log.Debug("Print Some status ...");
Once you have all of this set up and working. look through the Log4Net documentation on how to set up more useful logging. You can do a lot of different types of logging without changing the logging calls in your code at all.
Why not use a Logger object that write errors into a text file? You could come with some "priority" error messages such as: Logger.print(new priority("important"), "blabla");
This way, you could find in your file the exact time and all the message you want.
If you absolutely want the console, you could use the priority on the console.. so it would only prints what you tell the logger to print, such as network error, etc..