跳到主要內容

發表文章

目前顯示的是有「DotNet Core」標籤的文章

FluentD 實作 Error Log

FluentD 實作 Error Log 本篇將介紹使用 DotNet 專案 log4net 套件,紀錄的 log 針對 Error Level 的訊息透過FluentD 提取出來 在紀錄中 增加 trace ID 設入 MongoDB , 及加入 Slack 通知 延伸閱讀 FluentD 參數說明 FluentD 實作 Nginx Access Log FluentD 實作 Nginx Access Log 補充 log4net <?xml version="1.0" encoding="utf-8" ?> <configuration> <log4net> <appender name="All" type="log4net.Appender.RollingFileAppender"> <file value="/var/log/my.log" /> <appendToFile value="true" /> <rollingStyle value="Size" /> <datePattern value="yyyy-MM-dd" /> <maximumFileSize value="5MB" /> <maxSizeRollBackups value="10" /> <staticLogFileName value="true" /> <PreserveLogFileNameExtension value="true" /> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="[%date] [...

Slack 新增 Bot App

Create New App 1. Create New App 填入 App Name 及 選擇 workspace 2. 維護 Base Information 維護 App Name & Short description & App icon & background color 3. 維護 Oauth & Permissions Add an Oauth Scope incoming-webhook  channels:read This scope lets an app "View basic information about public channels in the workspace" chat:write:bot This scope lets an app "Send messages as your slack app" 4. Install App into your workspace Code Example Send messages example DotNet Code Send Message 2 Slack private void send2stalck(string path,string query,string header,string body,string message) { Dictionary dictQuery = new Dictionary (); dictQuery.Add("channel", @" slack channel "); dictQuery.Add("token", @" slack token "); dictQuery.Add("text", message); JArray jaFields = new JArray(); var joEnv = new JObject() { { "title", "env" }, { "value", ...

使用 RobotsTxtCore 建立 robot.txt & sitemap.xml

Nuget Link 透過 nuget 安裝 RobotsTxtCore >dotnet add package RobotsTxtCore --version 1.1.0 //Startup.cs public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { ... app.UseRobotsTxt(builder =>builder .AddSection(section => section .AddComment("Allow Googlebot") .AddUserAgent("Googlebot") .AddUserAgent("Googlebot-News") .AddUserAgent("Googlebot-Image") .AddUserAgent("Googlebot-Mobile") .AddUserAgent("Googlebot-Video") .AddUserAgent("Mediapartners-Google") .AddUserAgent("Adsbot-Google") .Allow("/") ) .AddSection(section => section .AddComment("Disallow the rest") .AddUserAgent("*") .AddCrawlDelay(TimeSpan.FromSeconds(10)) .Disallow("/") ) .AddSitemap("https://${domain}/sitemap.xml") ); }

meta tag 說明

meta tag 說明 1. <title></title> *建議中文保持在 30 個字元、英文 60 個字元以內 *可以用以下格式: 主要關鍵字  -  次要關鍵字 | 廠牌名稱 *每個頁面的 Title 都是唯一的 <title>MyDemo-@ViewData["Title"]</title> 2. <meta name='description' content='@ViewData["PageDescript"]' /> *建議中文保持在 80 個字元、英文 160 個字元以內 3. og 社群相關 tag og 全名為: Open Graph Protocol *在 og:title 設定的文字會當作分享 FB 時的標題。 3.1 og:image *大小不要超過 8 m *尺寸要大於 200px * 200px,否則連圖都抓不到 *如果圖片為長方形 建議最小尺寸 600px * 315px *如果圖片為正方形 建議最小尺寸 600px * 600px 程式化新增 meta tag //在DotNet Core Project中 新增目錄夾 Filters ,並新增MetaTagFilter.cs 檔案 using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.AspNetCore.Mvc; namespace WebProject.Filters { public class MetaTagAttribute : TypeFilterAttribute { public MetaTagAttribute( ) : base( typeof( MetaTagFilter ) ) { } public class MetaTagFilter : IActionFilter { private string title { get; set; } private string des...