stop
This commit is contained in:
@@ -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!
|
||||||
|
|
||||||

|

|
||||||
|
|||||||
@@ -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
BIN
content/blog/cli.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.9 MiB |
@@ -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
18
fix-dates.js
Normal 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();
|
||||||
Reference in New Issue
Block a user