This commit is contained in:
Tommy Parnell
2023-11-03 20:44:28 -04:00
parent fbcde3a3e4
commit c0559e20c7
31 changed files with 25 additions and 104 deletions

View File

@@ -17,4 +17,4 @@ So I figured out they have a cli in npm. Easy to install, just use npm to global
Now you have to call the cli, this is the flags I use `tinypng . -r -k YourKeyHere`. The period tells tinypng to look in the current directory for images, `-r` tells it to look recursively, or essentially to look through child directories as well, and the `-k YourKeyHere` is the key you get by logging in. On the free plan you get 500 compressions a month. Hopefully you will fall into the pit of success like I did! Now you have to call the cli, this is the flags I use `tinypng . -r -k YourKeyHere`. The period tells tinypng to look in the current directory for images, `-r` tells it to look recursively, or essentially to look through child directories as well, and the `-k YourKeyHere` is the key you get by logging in. On the free plan you get 500 compressions a month. Hopefully you will fall into the pit of success like I did!
![an image showing the tiny png results](3.png) ![an image showing the tiny png results](../img/Compressing-images-with-tinypng/3.png)

View File

@@ -1,101 +0,0 @@
---
title: 'Wiring up client side logs into c#/node.js logging frameworks'
tags:
- csharp
- logging
- library
permalink: /wiring-up-client-side-logs-into-c-sharp-logging-frameworks/
id: 60
updated: '2015-11-01 08:53:04'
date: 2015-11-01T13:22:07.000Z
---
Around a year ago I joined a new team where I work, and this team was starting to undertake a full rewrite of their code. We were going from a full c#/mvc app to a tiny c# api, and a very big SPA.
Early one one of the **huge** things to do was to make sure that our JavaScript error logs could land in our Log4Net infrastructure. I started to write something to do just that, and as I was coding I quickly realized this was less trivial that it sounded. We had something internal we could use, but it was tied to a lot of other code that we didn't want to pull in.
I started Bingling around and I stumbled across [jsnlog](http://jsnlog.com/). JSN log lets you quickly wire up your client side logs to your server. I have been able to get PR's into the [code base](https://github.com/mperdeck/jsnlog) and the guy behind it has been very friendly to me when I have had questions.
<!-- more -->
When you install the nuget package it drops this into your app_start.
```csharp
using System;
using System.Web.Routing;
using System.Web.Mvc;
[assembly: WebActivatorEx.PostApplicationStartMethod(
typeof(EmptyLog4Net.App_Start.JSNLogConfig), "PostStart")]
namespace EmptyLog4Net.App_Start {
public static class JSNLogConfig {
public static void PostStart() {
// Insert a route that ignores the jsnlog.logger route. That way,
// requests for jsnlog.logger will get through to the handler defined
// in web.config.
//
// The route must take this particular form, including the constraint,
// otherwise ActionLink will be confused by this route and generate the wrong URLs.
var jsnlogRoute = new Route("{*jsnloglogger}", new StopRoutingHandler());
jsnlogRoute.Constraints = new RouteValueDictionary {{ "jsnloglogger", @"jsnlog\.logger(/.*)?" }};
RouteTable.Routes.Insert(0, jsnlogRoute);
}
}
}
```
The whole thing is a html handler, so this code just simply makes sure the handler gets the first route.
When you are going to render a page you have to inject this razor:
`@Html.Raw(JSNLog.JavascriptLogging.Configure())` and the jsnlog javascript file.
Then whenever you want to log anything client side you can do the following.
```javascript
JL("jsLogger").fatal("client log message");
```
You can also set jsnlog as the global js error handler.
```javascript
window.onerror = function (errorMsg, url, lineNumber, column, errorObj) {
// Send object with all data to server side log, using severity fatal,
// from logger "onerrorLogger"
JL("onerrorLogger").fatalException({
"msg": "Exception!",
"errorMsg": errorMsg, "url": url,
"line number": lineNumber, "column": column
}, errorObj);
// Tell browser to run its own error handler as well
return false;
}
```
The docs are quite good, and it seems to work fine as a commonjs module (since we browserify things). The tool is super configurable through the web.config, and you can change the url it logs to.
```xml
<configuration>
...
<!-- Example of web.config based configuration -->
<jsnlog maxMessages="5">
<logger name="mylogger" level="INFO" />
<ajaxAppender name="myappender" batchSize="2" />
<logger name="mylogger2" appenders="myappender"/>
</jsnlog>
</configuration>
```
JSNLog is a great way to get your client side logs into your server infrastructure fast. The library has fantastic support for node, and every major [.NET logging framework](https://www.nuget.org/packages?q=jsnlog). Someone in the community even made a php plugin! The [examples](https://github.com/mperdeck/jsnlogSimpleWorkingDemos) are endless
Overall I am really pleased with JSNLog, it filled a need that I needed, and it meant I was able to focus on what I did best, not figure out how logging worked.

BIN
content/blog/cli.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.9 MiB

View File

@@ -8,7 +8,7 @@ tags:
So now that Windows server 2016 is [generally avalible](https://blogs.technet.microsoft.com/hybridcloud/2016/10/12/another-big-step-in-hybrid-cloud-windows-server-2016-general-availability/) for the first time ever windows users can now use containers. Ok, so what exactly are containers? Well more or less they are virtual operating systems that **share** the same kernel as the host OS. In regular VM's the hardware is shared between machines, but containers go a step further and share the kernel of the OS. Why does this matter? Well because you are sharing an existing kernel that is already running, your startup times are instantanious. To put this in perspective, this is virtualization at the OS level. So now that Windows server 2016 is [generally avalible](https://blogs.technet.microsoft.com/hybridcloud/2016/10/12/another-big-step-in-hybrid-cloud-windows-server-2016-general-availability/) for the first time ever windows users can now use containers. Ok, so what exactly are containers? Well more or less they are virtual operating systems that **share** the same kernel as the host OS. In regular VM's the hardware is shared between machines, but containers go a step further and share the kernel of the OS. Why does this matter? Well because you are sharing an existing kernel that is already running, your startup times are instantanious. To put this in perspective, this is virtualization at the OS level.
On Linux, containers have been a thing for a long time. This technology is called LXC. Docker itself is a layer ontop of various container platforms embedded in operating systems. On Linux, containers have been a thing for a long time. This technology is called LXC. Docker itself is a layer ontop of various container platforms embedded in operating systems.
<!-- more --> <!-- more -->
@@ -58,6 +58,6 @@ Even legacy applications can be improved with some kind of build automation. Sta
In my sample I created a gulp file that takes in a version number (which could be passed by our CI system). Patches the AssemblyInfo.cs files, restores nuget packages, and compiles down a docker image to be used later. All with the simple command of `gulp build --version 1.0.0` In my sample I created a gulp file that takes in a version number (which could be passed by our CI system). Patches the AssemblyInfo.cs files, restores nuget packages, and compiles down a docker image to be used later. All with the simple command of `gulp build --version 1.0.0`
The created docker image could easily be uploaded to some kind of storage. The created docker image could easily be uploaded to some kind of storage.

View File

@@ -108,6 +108,10 @@ module.exports = function(eleventyConfig) {
"njk", "njk",
"html", "html",
"liquid", "liquid",
"jpg",
"jpeg",
"gif",
"webp"
], ],
// Pre-process *.md files with: (default: `liquid`) // Pre-process *.md files with: (default: `liquid`)

18
fix-dates.js Normal file
View File

@@ -0,0 +1,18 @@
const fs = require('fs/promises');
async function run() {
const files = await fs.readdir('./content/blog');
console.log(files);
await Promise.all(files
.filter(file => file.endsWith('.md'))
.map(async (file) => {
// const fileContent = await fs.readFile(file, 'utf8');
// regex find the line date:
// const date = fileContent.match(/date: (.*)/);
// const parsedDate = date[1].split(' ');
}));
}
run();