├── Nuget ├── nuget.exe ├── Logo-Full.png ├── NetStash.1.3.0.nupkg └── nuget.bat ├── Versions ├── NetStash.1.2.0.nupkg └── NetStash.1.0.0.0.nupkg ├── NetStash ├── x64 │ └── SQLite.Interop.dll ├── x86 │ └── SQLite.Interop.dll ├── App.config ├── packages.config ├── Samples │ └── 01-JSON.Simple.yml ├── Storage │ ├── Entities │ │ └── Log.cs │ └── Proxy │ │ ├── BaseProxy.cs │ │ └── LogProxy.cs ├── Log │ ├── NetStashLogLevel.cs │ └── NetStashLog.cs ├── NetStashEvent.cs ├── Properties │ └── AssemblyInfo.cs ├── NetStash.csproj └── Worker │ └── TcpWorker.cs ├── Samples └── SampleApp │ ├── App.config │ ├── Program.cs │ ├── Properties │ └── AssemblyInfo.cs │ └── SampleApp.csproj ├── README.md ├── NetStash.sln ├── .gitattributes ├── .gitignore └── LICENSE /Nuget/nuget.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iquirino/NetStash/HEAD/Nuget/nuget.exe -------------------------------------------------------------------------------- /Nuget/Logo-Full.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iquirino/NetStash/HEAD/Nuget/Logo-Full.png -------------------------------------------------------------------------------- /Nuget/NetStash.1.3.0.nupkg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iquirino/NetStash/HEAD/Nuget/NetStash.1.3.0.nupkg -------------------------------------------------------------------------------- /Versions/NetStash.1.2.0.nupkg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iquirino/NetStash/HEAD/Versions/NetStash.1.2.0.nupkg -------------------------------------------------------------------------------- /NetStash/x64/SQLite.Interop.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iquirino/NetStash/HEAD/NetStash/x64/SQLite.Interop.dll -------------------------------------------------------------------------------- /NetStash/x86/SQLite.Interop.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iquirino/NetStash/HEAD/NetStash/x86/SQLite.Interop.dll -------------------------------------------------------------------------------- /Versions/NetStash.1.0.0.0.nupkg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iquirino/NetStash/HEAD/Versions/NetStash.1.0.0.0.nupkg -------------------------------------------------------------------------------- /Nuget/nuget.bat: -------------------------------------------------------------------------------- 1 | nuget pack ..\NetStash\NetStash.csproj -Prop Configuration=Release -Properties OutDir="..\\NetStash\\bin\\Release\\" -------------------------------------------------------------------------------- /NetStash/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Samples/SampleApp/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /NetStash/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /NetStash/Samples/01-JSON.Simple.yml: -------------------------------------------------------------------------------- 1 | input { 2 | tcp { 3 | port => 1233 4 | host => "10.32.12.52" 5 | } 6 | } 7 | filter { 8 | mutate { gsub => ["message", "@($NL$)@", "\r\n"] } 9 | json { source => message } 10 | } 11 | output { 12 | elasticsearch { 13 | 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /NetStash/Storage/Entities/Log.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace NetStash.Storage.Entities 8 | { 9 | public class Log 10 | { 11 | public long IdLog { get; set; } 12 | public string Message { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Samples/SampleApp/Program.cs: -------------------------------------------------------------------------------- 1 | using NetStash.Log; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading; 7 | using System.Threading.Tasks; 8 | 9 | namespace SampleApp 10 | { 11 | class Program 12 | { 13 | static void Main(string[] args) 14 | { 15 | NetStashLog log = new NetStashLog("brspomelkq01.la.imtn.com", 1233, "NSTest", "NSTestLog"); 16 | Dictionary vals = new Dictionary(); 17 | 18 | log.Error("Testing", vals); 19 | 20 | Thread.Sleep(50000); 21 | 22 | log.Stop(); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /NetStash/Log/NetStashLogLevel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace NetStash.Log 8 | { 9 | public enum NetStashLogLevel 10 | { 11 | // 12 | // Summary: 13 | // Anything and everything you might want to know about a running block of code. 14 | Verbose, 15 | // 16 | // Summary: 17 | // Internal system events that aren't necessarily observable from the outside. 18 | Debug, 19 | // 20 | // Summary: 21 | // The lifeblood of operational intelligence - things happen. 22 | Information, 23 | // 24 | // Summary: 25 | // Service is degraded or endangered. 26 | Warning, 27 | // 28 | // Summary: 29 | // Functionality is unavailable, invariants are broken or data is lost. 30 | Error, 31 | // 32 | // Summary: 33 | // If you have a pager, it goes off when one of these occurs. 34 | Fatal 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /NetStash/NetStashEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace NetStash 8 | { 9 | [Newtonsoft.Json.JsonObject] 10 | public class NetStashEvent 11 | { 12 | [Newtonsoft.Json.JsonProperty(PropertyName = "timestamp")] 13 | public DateTime Timestamp { get; set; } 14 | [Newtonsoft.Json.JsonProperty(PropertyName = "message")] 15 | public string Message { get; set; } 16 | 17 | [Newtonsoft.Json.JsonProperty(PropertyName = "exception-details")] 18 | public string ExceptionDetails { get; set; } 19 | 20 | [Newtonsoft.Json.JsonProperty(PropertyName = "source")] 21 | public string Source { get; set; } 22 | 23 | [Newtonsoft.Json.JsonProperty(PropertyName = "level")] 24 | public string Level { get; set; } 25 | 26 | [Newtonsoft.Json.JsonProperty(PropertyName = "machine-name")] 27 | public string Machine { get; set; } 28 | 29 | [Newtonsoft.Json.JsonProperty(PropertyName = "index-name")] 30 | public string Index { get; set; } 31 | 32 | [Newtonsoft.Json.JsonProperty(PropertyName = "fields")] 33 | public Dictionary Fields { get; set; } 34 | 35 | public NetStashEvent() 36 | { 37 | Timestamp = DateTime.Now; 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Samples/SampleApp/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("SampleApp")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Hewlett-Packard Company")] 12 | [assembly: AssemblyProduct("SampleApp")] 13 | [assembly: AssemblyCopyright("Copyright © Hewlett-Packard Company 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("8f850af6-399f-48b5-85a9-8cad98ec34e0")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /NetStash/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("NetStash")] 9 | [assembly: AssemblyDescription("Logstash sender for .NET - Send events to logstash instance via TCP/TLS")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Igor Quirino @ WareBoss LTDA - ME")] 12 | [assembly: AssemblyProduct("NetStash")] 13 | [assembly: AssemblyCopyright("Copyright © WareBoss 2019")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("0269533a-f063-4572-8c54-9b3b34e6eab9")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.3.0.0")] 36 | [assembly: AssemblyFileVersion("1.3.0.0")] -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # NetStash 2 | Logstash sender for .NET 3 | 4 | Send events to logstash instance via TCP 5 | 6 | Saves all events into a sqlite database to prevent loss from network issues 7 | 8 | Automatic synchronization when network connection is stablished 9 | 10 | ## Installation 11 | 12 | Nugget Package: https://www.nuget.org/packages/NetStash 13 | 14 | ``` 15 | PM > Install-Package NetStash 16 | ``` 17 | 18 | ## Usage 19 | 20 | ``` 21 | NetStashLog log = new NetStashLog("myhostname", 1233, "NSTest", "NSTestLog"); 22 | 23 | Dictionary vals = new Dictionary(); 24 | //Additional fields 25 | vals.Add("customerid", "1235"); 26 | 27 | log.Error("Testing", vals); 28 | ``` 29 | 30 | ## TLS Certificates 31 | 32 | Note: certificateValidation = null >> Certificate validation will be discarded 33 | 34 | ``` 35 | NetStashLog log = new NetStashLog("myhostname", 1233, "NSTest", "NSTestLog", SslProtocols.Tls12, certificates, "domain.certificate.com", null); 36 | 37 | Dictionary vals = new Dictionary(); 38 | //Additional fields 39 | vals.Add("customerid", "1235"); 40 | 41 | log.Error("Testing", vals); 42 | ``` 43 | 44 | ## Logstash config 45 | 46 | ``` 47 | input { 48 | tcp { 49 | port => 1233 50 | host => "192.168.0.151" 51 | codec => json 52 | } 53 | } 54 | filter { 55 | mutate { gsub => ["message", "@($NL$)@", "\r\n"] } 56 | } 57 | output { 58 | elasticsearch { 59 | 60 | } 61 | } 62 | 63 | ``` 64 | 65 | ## When to use 66 | 67 | This project will work with ALL versions of elasticsearch. 68 | 69 | If you just want to send log data, i recommend you to use NetStash. 70 | 71 | If you are using elasticsearch 7+ and need to log error details: 72 | I strongly recommend you to use https://github.com/elastic/apm-agent-dotnet Apm Agent Dotnet. 73 | (I'm a contributor of this too) 74 | 75 | ## Who is using 76 | 77 | Iron Mountain Brasil 78 | - All internals logs systems. 79 | -------------------------------------------------------------------------------- /NetStash/Storage/Proxy/BaseProxy.cs: -------------------------------------------------------------------------------- 1 | using System.Data; 2 | using System.IO; 3 | using System.Reflection; 4 | 5 | namespace NetStash.Storage.Proxy 6 | { 7 | public class BaseProxy 8 | { 9 | private static string dbFilePath = "./NetStash.db"; 10 | private static bool initialized = false; 11 | private static object _lock = new object(); 12 | 13 | public BaseProxy() 14 | { 15 | lock (_lock) 16 | { 17 | if (initialized) return; 18 | 19 | Directory.CreateDirectory("x86"); 20 | if (!File.Exists("x86\\SQLite.Interop.dll")) 21 | this.SaveToDisk("NetStash.x86.SQLite.Interop.dll", "x86\\SQLite.Interop.dll"); 22 | 23 | Directory.CreateDirectory("x64"); 24 | if (!File.Exists("x64\\SQLite.Interop.dll")) 25 | this.SaveToDisk("NetStash.x64.SQLite.Interop.dll", "x64\\SQLite.Interop.dll"); 26 | 27 | if (!File.Exists(dbFilePath)) 28 | { 29 | System.Data.SQLite.SQLiteConnection.CreateFile(dbFilePath); 30 | 31 | using (var cnn = (System.Data.SQLite.SQLiteConnection)this.GetConnection()) 32 | { 33 | cnn.Open(); 34 | var cmd = new System.Data.SQLite.SQLiteCommand("CREATE TABLE \"Log\" ([IdLog] integer, [Message] nvarchar, PRIMARY KEY(IdLog));", cnn); 35 | cmd.ExecuteNonQuery(); 36 | } 37 | } 38 | else 39 | { 40 | using (var cnn = (System.Data.SQLite.SQLiteConnection)this.GetConnection()) 41 | using (System.Data.SQLite.SQLiteCommand command = cnn.CreateCommand()) 42 | { 43 | command.CommandText = "vacuum;"; 44 | command.ExecuteNonQuery(); 45 | } 46 | } 47 | 48 | initialized = true; 49 | } 50 | } 51 | 52 | internal IDbConnection GetConnection() 53 | { 54 | return new System.Data.SQLite.SQLiteConnection(string.Format("Data Source={0};Version=3;", dbFilePath)); 55 | } 56 | 57 | private void SaveToDisk(string file, string name) 58 | { 59 | using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(file)) 60 | using (var fileStream = new FileStream(name, FileMode.CreateNew)) 61 | for (int i = 0; i < stream.Length; i++) 62 | fileStream.WriteByte((byte)stream.ReadByte()); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /NetStash.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28010.2048 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetStash", "NetStash\NetStash.csproj", "{0269533A-F063-4572-8C54-9B3B34E6EAB9}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{0D9E997E-EBDE-4333-A929-055A40BB86E8}" 9 | EndProject 10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{F7B5EA42-9917-44B8-A290-36ADA2F39662}" 11 | EndProject 12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleApp", "Samples\SampleApp\SampleApp.csproj", "{8F850AF6-399F-48B5-85A9-8CAD98EC34E0}" 13 | EndProject 14 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Git", "Git", "{076DE81D-636C-4A92-BA30-47F66718B251}" 15 | ProjectSection(SolutionItems) = preProject 16 | .gitattributes = .gitattributes 17 | .gitignore = .gitignore 18 | LICENSE = LICENSE 19 | README.md = README.md 20 | EndProjectSection 21 | EndProject 22 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Nuget", "Nuget", "{6B7E0594-D317-42B0-ADD4-37FF60660FD3}" 23 | ProjectSection(SolutionItems) = preProject 24 | Nuget\Logo-Full.png = Nuget\Logo-Full.png 25 | Nuget\nuget.bat = Nuget\nuget.bat 26 | Nuget\nuget.exe = Nuget\nuget.exe 27 | EndProjectSection 28 | EndProject 29 | Global 30 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 31 | Debug|Any CPU = Debug|Any CPU 32 | Release|Any CPU = Release|Any CPU 33 | EndGlobalSection 34 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 35 | {0269533A-F063-4572-8C54-9B3B34E6EAB9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 36 | {0269533A-F063-4572-8C54-9B3B34E6EAB9}.Debug|Any CPU.Build.0 = Debug|Any CPU 37 | {0269533A-F063-4572-8C54-9B3B34E6EAB9}.Release|Any CPU.ActiveCfg = Release|Any CPU 38 | {0269533A-F063-4572-8C54-9B3B34E6EAB9}.Release|Any CPU.Build.0 = Release|Any CPU 39 | {8F850AF6-399F-48B5-85A9-8CAD98EC34E0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 40 | {8F850AF6-399F-48B5-85A9-8CAD98EC34E0}.Debug|Any CPU.Build.0 = Debug|Any CPU 41 | {8F850AF6-399F-48B5-85A9-8CAD98EC34E0}.Release|Any CPU.ActiveCfg = Release|Any CPU 42 | {8F850AF6-399F-48B5-85A9-8CAD98EC34E0}.Release|Any CPU.Build.0 = Release|Any CPU 43 | EndGlobalSection 44 | GlobalSection(SolutionProperties) = preSolution 45 | HideSolutionNode = FALSE 46 | EndGlobalSection 47 | GlobalSection(NestedProjects) = preSolution 48 | {8F850AF6-399F-48B5-85A9-8CAD98EC34E0} = {F7B5EA42-9917-44B8-A290-36ADA2F39662} 49 | EndGlobalSection 50 | GlobalSection(ExtensibilityGlobals) = postSolution 51 | SolutionGuid = {E8683FA7-B90C-4BC0-9EA4-338B63EE0AE0} 52 | EndGlobalSection 53 | EndGlobal 54 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /Samples/SampleApp/SampleApp.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {8F850AF6-399F-48B5-85A9-8CAD98EC34E0} 8 | Exe 9 | Properties 10 | SampleApp 11 | SampleApp 12 | v4.6.1 13 | 512 14 | true 15 | 16 | 17 | 18 | AnyCPU 19 | true 20 | full 21 | false 22 | bin\Debug\ 23 | DEBUG;TRACE 24 | prompt 25 | 4 26 | 27 | 28 | AnyCPU 29 | pdbonly 30 | true 31 | bin\Release\ 32 | TRACE 33 | prompt 34 | 4 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | {0269533a-f063-4572-8c54-9b3b34e6eab9} 56 | NetStash 57 | 58 | 59 | 60 | 67 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | build/ 19 | bld/ 20 | [Bb]in/ 21 | [Oo]bj/ 22 | 23 | # Visual Studio 2015 cache/options directory 24 | .vs/ 25 | 26 | # MSTest test Results 27 | [Tt]est[Rr]esult*/ 28 | [Bb]uild[Ll]og.* 29 | 30 | # NUNIT 31 | *.VisualState.xml 32 | TestResult.xml 33 | 34 | # Build Results of an ATL Project 35 | [Dd]ebugPS/ 36 | [Rr]eleasePS/ 37 | dlldata.c 38 | 39 | # DNX 40 | project.lock.json 41 | artifacts/ 42 | 43 | *_i.c 44 | *_p.c 45 | *_i.h 46 | *.ilk 47 | *.meta 48 | *.obj 49 | *.pch 50 | *.pdb 51 | *.pgc 52 | *.pgd 53 | *.rsp 54 | *.sbr 55 | *.tlb 56 | *.tli 57 | *.tlh 58 | *.tmp 59 | *.tmp_proj 60 | *.log 61 | *.vspscc 62 | *.vssscc 63 | .builds 64 | *.pidb 65 | *.svclog 66 | *.scc 67 | 68 | # Chutzpah Test files 69 | _Chutzpah* 70 | 71 | # Visual C++ cache files 72 | ipch/ 73 | *.aps 74 | *.ncb 75 | *.opensdf 76 | *.sdf 77 | *.cachefile 78 | 79 | # Visual Studio profiler 80 | *.psess 81 | *.vsp 82 | *.vspx 83 | 84 | # TFS 2012 Local Workspace 85 | $tf/ 86 | 87 | # Guidance Automation Toolkit 88 | *.gpState 89 | 90 | # ReSharper is a .NET coding add-in 91 | _ReSharper*/ 92 | *.[Rr]e[Ss]harper 93 | *.DotSettings.user 94 | 95 | # JustCode is a .NET coding add-in 96 | .JustCode 97 | 98 | # TeamCity is a build add-in 99 | _TeamCity* 100 | 101 | # DotCover is a Code Coverage Tool 102 | *.dotCover 103 | 104 | # NCrunch 105 | _NCrunch_* 106 | .*crunch*.local.xml 107 | 108 | # MightyMoose 109 | *.mm.* 110 | AutoTest.Net/ 111 | 112 | # Web workbench (sass) 113 | .sass-cache/ 114 | 115 | # Installshield output folder 116 | [Ee]xpress/ 117 | 118 | # DocProject is a documentation generator add-in 119 | DocProject/buildhelp/ 120 | DocProject/Help/*.HxT 121 | DocProject/Help/*.HxC 122 | DocProject/Help/*.hhc 123 | DocProject/Help/*.hhk 124 | DocProject/Help/*.hhp 125 | DocProject/Help/Html2 126 | DocProject/Help/html 127 | 128 | # Click-Once directory 129 | publish/ 130 | 131 | # Publish Web Output 132 | *.[Pp]ublish.xml 133 | *.azurePubxml 134 | ## TODO: Comment the next line if you want to checkin your 135 | ## web deploy settings but do note that will include unencrypted 136 | ## passwords 137 | #*.pubxml 138 | 139 | *.publishproj 140 | 141 | # NuGet Packages 142 | # The packages folder can be ignored because of Package Restore 143 | **/packages/* 144 | # except build/, which is used as an MSBuild target. 145 | !**/packages/build/ 146 | # Uncomment if necessary however generally it will be regenerated when needed 147 | #!**/packages/repositories.config 148 | 149 | # Windows Azure Build Output 150 | csx/ 151 | *.build.csdef 152 | 153 | # Windows Store app package directory 154 | AppPackages/ 155 | 156 | # Visual Studio cache files 157 | # files ending in .cache can be ignored 158 | *.[Cc]ache 159 | # but keep track of directories ending in .cache 160 | !*.[Cc]ache/ 161 | 162 | # Others 163 | ClientBin/ 164 | [Ss]tyle[Cc]op.* 165 | ~$* 166 | *~ 167 | *.dbmdl 168 | *.dbproj.schemaview 169 | *.pfx 170 | *.publishsettings 171 | node_modules/ 172 | orleans.codegen.cs 173 | 174 | # RIA/Silverlight projects 175 | Generated_Code/ 176 | 177 | # Backup & report files from converting an old project file 178 | # to a newer Visual Studio version. Backup files are not needed, 179 | # because we have git ;-) 180 | _UpgradeReport_Files/ 181 | Backup*/ 182 | UpgradeLog*.XML 183 | UpgradeLog*.htm 184 | 185 | # SQL Server files 186 | *.mdf 187 | *.ldf 188 | 189 | # Business Intelligence projects 190 | *.rdl.data 191 | *.bim.layout 192 | *.bim_*.settings 193 | 194 | # Microsoft Fakes 195 | FakesAssemblies/ 196 | 197 | # Node.js Tools for Visual Studio 198 | .ntvs_analysis.dat 199 | 200 | # Visual Studio 6 build log 201 | *.plg 202 | 203 | # Visual Studio 6 workspace options file 204 | *.opt 205 | 206 | # LightSwitch generated files 207 | GeneratedArtifacts/ 208 | _Pvt_Extensions/ 209 | ModelManifest.xml 210 | -------------------------------------------------------------------------------- /NetStash/Storage/Proxy/LogProxy.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Data; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace NetStash.Storage.Proxy 9 | { 10 | public class LogProxy : BaseProxy 11 | { 12 | public LogProxy() : base() 13 | { 14 | 15 | } 16 | 17 | public void Add(NetStashEvent log) 18 | { 19 | Entities.Log addLog = new Entities.Log(); 20 | addLog.Message = Newtonsoft.Json.JsonConvert.SerializeObject(log); 21 | 22 | using (IDbConnection db = base.GetConnection()) 23 | using (IDbCommand cmd = db.CreateCommand()) 24 | { 25 | cmd.CommandText = "INSERT INTO Log (Message) VALUES (@Message)"; 26 | cmd.CommandType = CommandType.Text; 27 | IDbDataParameter pMessage = cmd.CreateParameter(); 28 | pMessage.ParameterName = "@Message"; 29 | pMessage.Value = addLog.Message; 30 | cmd.Parameters.Add(pMessage); 31 | cmd.Prepare(); 32 | db.Open(); 33 | cmd.ExecuteNonQuery(); 34 | } 35 | } 36 | 37 | public NetStashEvent Get(out long id) 38 | { 39 | Entities.Log getLog = null; 40 | using (IDbConnection db = base.GetConnection()) 41 | using (IDbCommand cmd = db.CreateCommand()) 42 | { 43 | cmd.CommandText = "SELECT IdLog, Message from Log order by IdLog asc LIMIT 1"; 44 | cmd.CommandType = CommandType.Text; 45 | cmd.Prepare(); 46 | db.Open(); 47 | 48 | IDataReader reader = cmd.ExecuteReader(); 49 | while (reader.Read()) 50 | { 51 | getLog = new Entities.Log(); 52 | getLog.IdLog = reader.GetInt64(reader.GetOrdinal("IdLog")); 53 | getLog.Message = reader.IsDBNull(reader.GetOrdinal("Message")) ? null : reader.GetString(reader.GetOrdinal("Message")); 54 | 55 | } 56 | } 57 | 58 | if (getLog == null) 59 | { 60 | id = -1; 61 | return null; 62 | } 63 | 64 | id = getLog.IdLog; 65 | 66 | return Newtonsoft.Json.JsonConvert.DeserializeObject(getLog.Message); 67 | } 68 | 69 | public Dictionary GetList(int count = 100) 70 | { 71 | Dictionary ret = new Dictionary(); 72 | 73 | List evs = new List(); 74 | 75 | using (IDbConnection db = base.GetConnection()) 76 | using (IDbCommand cmd = db.CreateCommand()) 77 | { 78 | cmd.CommandText = "SELECT IdLog, Message from Log order by IdLog asc LIMIT " + count; 79 | cmd.CommandType = CommandType.Text; 80 | cmd.Prepare(); 81 | db.Open(); 82 | 83 | IDataReader reader = cmd.ExecuteReader(); 84 | while (reader.Read()) 85 | { 86 | Entities.Log log = new Entities.Log(); 87 | 88 | log.IdLog = reader.GetInt64(reader.GetOrdinal("IdLog")); 89 | log.Message = reader.IsDBNull(reader.GetOrdinal("Message")) ? null : reader.GetString(reader.GetOrdinal("Message")); 90 | 91 | evs.Add(log); 92 | } 93 | } 94 | 95 | foreach (Entities.Log item in evs) 96 | ret.Add(item.IdLog, item.Message); 97 | 98 | return ret; 99 | } 100 | 101 | public void Delete(long id) 102 | { 103 | if (id < 0) return; 104 | 105 | using (IDbConnection db = base.GetConnection()) 106 | using (IDbCommand cmd = db.CreateCommand()) 107 | { 108 | cmd.CommandText = "DELETE FROM Log WHERE IdLog = @IdLog"; 109 | cmd.CommandType = CommandType.Text; 110 | IDbDataParameter pIdLog = cmd.CreateParameter(); 111 | pIdLog.ParameterName = "@IdLog"; 112 | pIdLog.Value = id; 113 | cmd.Parameters.Add(pIdLog); 114 | cmd.Prepare(); 115 | db.Open(); 116 | cmd.ExecuteNonQuery(); 117 | } 118 | } 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /NetStash/NetStash.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {0269533A-F063-4572-8C54-9B3B34E6EAB9} 8 | Library 9 | Properties 10 | NetStash 11 | NetStash 12 | v4.6.1 13 | 512 14 | 15 | 16 | 17 | 18 | 19 | true 20 | full 21 | false 22 | bin\Debug\ 23 | DEBUG;TRACE 24 | prompt 25 | 4 26 | false 27 | 28 | 29 | pdbonly 30 | true 31 | bin\Release\ 32 | TRACE 33 | prompt 34 | 4 35 | false 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | ..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll 44 | 45 | 46 | 47 | 48 | 49 | 50 | ..\packages\System.Data.SQLite.Core.1.0.109.2\lib\net46\System.Data.SQLite.dll 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | Designer 74 | 75 | 76 | 77 | 78 | 79 | 80 | Always 81 | 82 | 83 | Always 84 | 85 | 86 | 87 | 88 | 89 | 90 | This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. 91 | 92 | 93 | 94 | 101 | -------------------------------------------------------------------------------- /NetStash/Log/NetStashLog.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Net.Security; 5 | using System.Security.Authentication; 6 | using System.Security.Cryptography.X509Certificates; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | 10 | namespace NetStash.Log 11 | { 12 | public class NetStashLog 13 | { 14 | private string logstashIp = string.Empty; 15 | private int logstashPort = -1; 16 | private string logname = string.Empty; 17 | private string system = string.Empty; 18 | 19 | public NetStashLog(string logstashIp, int logstashPort, SslProtocols protocol, X509CertificateCollection certificates, string serverCertificateName, string system, string logname = "NetStashLogs", RemoteCertificateValidationCallback certificateValidation = null) 20 | { 21 | if (string.IsNullOrWhiteSpace(logstashIp)) 22 | throw new ArgumentNullException("logstashIp"); 23 | 24 | if (string.IsNullOrWhiteSpace(logname)) 25 | throw new ArgumentNullException("logname"); 26 | 27 | if (string.IsNullOrWhiteSpace(system)) 28 | throw new ArgumentNullException("system"); 29 | 30 | Worker.TcpWorker.Initialize(logstashIp, logstashPort, protocol, certificates, serverCertificateName, certificateValidation); 31 | 32 | this.logstashIp = logstashIp; 33 | this.logstashPort = logstashPort; 34 | this.logname = logname; 35 | this.system = system; 36 | } 37 | 38 | public NetStashLog(string logstashIp, int logstashPort, string system, string logname = "NetStashLogs") 39 | { 40 | if (string.IsNullOrWhiteSpace(logstashIp)) 41 | throw new ArgumentNullException("logstashIp"); 42 | 43 | if (string.IsNullOrWhiteSpace(logname)) 44 | throw new ArgumentNullException("logname"); 45 | 46 | if (string.IsNullOrWhiteSpace(system)) 47 | throw new ArgumentNullException("system"); 48 | 49 | Worker.TcpWorker.Initialize(logstashIp, logstashPort); 50 | 51 | this.logstashIp = logstashIp; 52 | this.logstashPort = logstashPort; 53 | this.logname = logname; 54 | this.system = system; 55 | } 56 | 57 | public void Stop() 58 | { 59 | Worker.TcpWorker.Stop(); 60 | } 61 | 62 | public void Restart() 63 | { 64 | Worker.TcpWorker.Restart(); 65 | } 66 | 67 | public void Verbose(string message, Dictionary values = null) 68 | { 69 | NetStashEvent netStashEvent = new NetStashEvent(); 70 | netStashEvent.Level = NetStashLogLevel.Verbose.ToString(); 71 | netStashEvent.Message = message; 72 | netStashEvent.Fields = values; 73 | 74 | this.AddSendToLogstash(netStashEvent); 75 | } 76 | 77 | public void Debug(string message, Dictionary values = null) 78 | { 79 | NetStashEvent netStashEvent = new NetStashEvent(); 80 | netStashEvent.Level = NetStashLogLevel.Debug.ToString(); 81 | netStashEvent.Message = message; 82 | netStashEvent.Fields = values; 83 | 84 | this.AddSendToLogstash(netStashEvent); 85 | } 86 | 87 | public void Information(string message, Dictionary values = null) 88 | { 89 | NetStashEvent netStashEvent = new NetStashEvent(); 90 | netStashEvent.Level = NetStashLogLevel.Information.ToString(); 91 | netStashEvent.Message = message; 92 | netStashEvent.Fields = values; 93 | 94 | this.AddSendToLogstash(netStashEvent); 95 | } 96 | 97 | public void Warning(string message, Dictionary values = null) 98 | { 99 | NetStashEvent netStashEvent = new NetStashEvent(); 100 | netStashEvent.Level = NetStashLogLevel.Warning.ToString(); 101 | netStashEvent.Message = message; 102 | netStashEvent.Fields = values; 103 | 104 | this.AddSendToLogstash(netStashEvent); 105 | } 106 | 107 | 108 | internal void InternalError(string message, Dictionary values = null) 109 | { 110 | NetStashEvent netStashEvent = new NetStashEvent(); 111 | netStashEvent.Level = NetStashLogLevel.Error.ToString(); 112 | netStashEvent.Message = message; 113 | netStashEvent.Fields = values; 114 | 115 | this.AddSendToLogstash(netStashEvent, false); 116 | } 117 | 118 | public void Error(Exception exception, Dictionary values) 119 | { 120 | NetStashEvent netStashEvent = new NetStashEvent(); 121 | netStashEvent.Level = NetStashLogLevel.Error.ToString(); 122 | netStashEvent.Message = exception.Message; 123 | netStashEvent.ExceptionDetails = exception.StackTrace; 124 | netStashEvent.Fields = values; 125 | 126 | this.AddSendToLogstash(netStashEvent); 127 | } 128 | 129 | public void Error(string message, Dictionary values = null) 130 | { 131 | NetStashEvent netStashEvent = new NetStashEvent(); 132 | netStashEvent.Level = NetStashLogLevel.Error.ToString(); 133 | netStashEvent.Message = message; 134 | netStashEvent.Fields = values; 135 | 136 | this.AddSendToLogstash(netStashEvent); 137 | } 138 | 139 | public void Fatal(string message, Dictionary values = null) 140 | { 141 | NetStashEvent netStashEvent = new NetStashEvent(); 142 | netStashEvent.Level = NetStashLogLevel.Fatal.ToString(); 143 | netStashEvent.Message = message; 144 | netStashEvent.Fields = values; 145 | 146 | this.AddSendToLogstash(netStashEvent); 147 | } 148 | 149 | private void AddSendToLogstash(NetStashEvent e, bool run = true) 150 | { 151 | e.Machine = Environment.MachineName; 152 | e.Source = system; 153 | e.Index = logname; 154 | 155 | Storage.Proxy.LogProxy proxy = new Storage.Proxy.LogProxy(); 156 | proxy.Add(e); 157 | 158 | if (run) 159 | Worker.TcpWorker.Run(); 160 | } 161 | } 162 | } 163 | -------------------------------------------------------------------------------- /NetStash/Worker/TcpWorker.cs: -------------------------------------------------------------------------------- 1 | using NetStash.Log; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Net.Security; 7 | using System.Net.Sockets; 8 | using System.Security.Authentication; 9 | using System.Security.Cryptography.X509Certificates; 10 | using System.Text; 11 | using System.Threading.Tasks; 12 | 13 | namespace NetStash.Worker 14 | { 15 | public static class TcpWorker 16 | { 17 | static string logstashIp = string.Empty; 18 | static int logstashPort = -1; 19 | 20 | static SslProtocols sslProtocol = SslProtocols.None; 21 | static X509CertificateCollection certificateCollection = null; 22 | static RemoteCertificateValidationCallback remoteCertificateValidation = null; 23 | static string serverCertName = null; 24 | 25 | static object _lock = new object(); 26 | static bool isRunning = false; 27 | static Task run; 28 | 29 | static bool stopCalled = false; 30 | 31 | public static void Initialize(string logstashAddressIp, int logstashAddressPort, SslProtocols protocol, X509CertificateCollection certificates, string serverCertificateName, RemoteCertificateValidationCallback certificateValidation = null) 32 | { 33 | InitializeWorker(logstashAddressIp, logstashAddressPort, protocol, certificates, serverCertificateName, certificateValidation); 34 | } 35 | 36 | public static void Initialize(string logstashAddressIp, int logstashAddressPort) 37 | { 38 | InitializeWorker(logstashAddressIp, logstashAddressPort); 39 | } 40 | 41 | private static void InitializeWorker(string logstashAddressIp, int logstashAddressPort, SslProtocols protocol = SslProtocols.None, X509CertificateCollection certificates = null, string serverCertificateName = null, RemoteCertificateValidationCallback certificateValidation = null) 42 | { 43 | if (string.IsNullOrWhiteSpace(logstashAddressIp)) 44 | throw new ArgumentNullException("logstashAddressIp", "You need to inform a host address"); 45 | 46 | if (logstashAddressPort <= 0) 47 | throw new ArgumentOutOfRangeException("logstashAddressPort", logstashAddressPort, "You need to inform a valid port number"); 48 | 49 | logstashIp = logstashAddressIp; 50 | logstashPort = logstashAddressPort; 51 | sslProtocol = protocol; 52 | 53 | if (sslProtocol != SslProtocols.None) 54 | { 55 | if(certificates == null || certificates.Count <= 0) 56 | throw new ArgumentNullException("certificates", "You need to inform a certificate to be used"); 57 | 58 | certificateCollection = certificates; 59 | serverCertName = serverCertificateName; 60 | 61 | if (remoteCertificateValidation != null) 62 | remoteCertificateValidation = certificateValidation; 63 | } 64 | 65 | Run(); 66 | } 67 | 68 | public static void Run() 69 | { 70 | if (stopCalled) return; 71 | 72 | if (run == null || run.Status != TaskStatus.Running) 73 | { 74 | run = Task.Factory.StartNew(() => 75 | { 76 | lock (_lock) 77 | isRunning = true; 78 | 79 | while (isRunning && !stopCalled) 80 | { 81 | try 82 | { 83 | Runner(); 84 | } 85 | catch (Exception ex) 86 | { 87 | NetStashLog log = new NetStashLog(logstashIp, logstashPort, "NetStash", "NetStash"); 88 | log.InternalError("Logstash communication error: " + ex.Message); 89 | } 90 | } 91 | }); 92 | } 93 | } 94 | 95 | internal static void Restart() 96 | { 97 | lock (_lock) 98 | isRunning = true; 99 | 100 | stopCalled = false; 101 | 102 | Run(); 103 | } 104 | 105 | internal static void Stop() 106 | { 107 | lock (_lock) 108 | isRunning = false; 109 | 110 | stopCalled = true; 111 | 112 | if (run != null) run.Wait(); 113 | } 114 | 115 | private static void Runner() 116 | { 117 | Storage.Proxy.LogProxy proxy = new Storage.Proxy.LogProxy(); 118 | Dictionary evs; 119 | 120 | lock (_lock) 121 | { 122 | evs = proxy.GetList(); 123 | if (evs.Count <= 0) 124 | { 125 | isRunning = false; 126 | return; 127 | } 128 | } 129 | 130 | Send(evs, RemoveEntry); 131 | } 132 | 133 | private static void RemoveEntry(long id) 134 | { 135 | Storage.Proxy.LogProxy proxy = new Storage.Proxy.LogProxy(); 136 | proxy.Delete(id); 137 | } 138 | 139 | private static void Send(Dictionary evs, Action after) 140 | { 141 | using (TcpClient client = new TcpClient(logstashIp, logstashPort)) 142 | { 143 | if (sslProtocol == SslProtocols.None) 144 | { 145 | using (StreamWriter writer = new StreamWriter(client.GetStream())) 146 | { 147 | foreach (KeyValuePair ev in evs) 148 | { 149 | writer.WriteLine(ev.Value.Replace(Environment.NewLine, "@($NL$)@")); 150 | after(ev.Key); 151 | } 152 | } 153 | } 154 | else 155 | { 156 | using (var writer = new SslStream(client.GetStream(), false, remoteCertificateValidation ?? Default_CertificateValidation)) 157 | { 158 | writer.AuthenticateAsClient(serverCertName, certificateCollection, sslProtocol, remoteCertificateValidation == null); 159 | foreach (KeyValuePair ev in evs) 160 | { 161 | byte[] data = Encoding.Default.GetBytes(ev.Value.Replace(Environment.NewLine, "@($NL$)@")); 162 | writer.Write(data); 163 | after(ev.Key); 164 | } 165 | } 166 | } 167 | } 168 | } 169 | 170 | private static bool Default_CertificateValidation(Object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) 171 | { 172 | if (sslPolicyErrors == SslPolicyErrors.None) { return true; } 173 | if (sslPolicyErrors == SslPolicyErrors.RemoteCertificateChainErrors) { return true; } 174 | return false; 175 | } 176 | } 177 | } 178 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------